Tuesday, December 28, 2010

Markov Chain generator

As it turns out, with a sufficiently dense input text, a Markov Chain generator is actually reasonably easy to implement.

From page 62 of The Practice of Programming:

set w1 and w2 to the first two words in the text

print w1 and w2


randomly choose w3, one of the successors of prefix w1 w2 in the text
print w3
print w1 and w2 by w2 and w3
repeat loop

No comments:

Post a Comment