Random Text

About the system

For a laugh, I (Mattias Fagerlund) implemented a system that generates random text using Markov Chains. This page describes the process. My system is slightly different in that I use three word chains (the two previous words decide what the next word shall be).

Here's an excellent desciption from that page;

Here's the idea: scan through the text and create a huge frequency table of what words come after what other words. That is, say the words "Up the" occur six times in the text; four of those times they're followed by "tree", and twice by "ladder". We record this information in the table. And so on for every pair of words in the text.

Then, we generate output which is random, but has the same distribution of word groups. This is very easy given the table. Start with a seed, which is the first two words of the original text; for convenience, let's say this is "Up the". Then we roll a six-sided die with "tree" written on four sides and "ladder" written on two sides. Say it comes up "ladder"; print that word next. Now we shift one word ahead, and find "the ladder" in the table, and roll the dice again. Repeat until we have as many words as we're in the mood for.

Try it out

Feel free to generate a few random texts for yourself. Each text is unique.

If you want to study the base texts used to generate the random texts, here they are;

Click here to get back to Mattias main page.