This is an example taken from The Practice of Programming, by Brian W. Kernighan and Rob Pike.
Basically we treat a text as a string of words generated from a Markov chain. We then learn the rules and try to generate random sentenses from them. The authors already presented several implementations (beautifully coded) in C/C++/Java/Awk/Perl.
Copy and paste the learning text to the box below.
words.
Markov chain order:
Output:
Some example text:
† The script can handle Asian text as well.
The source code of the above Javascript markov.js.
A similar Python script markov.py.