The basic idea behind the text above is:
1. use some original text to calculate probabilities that given word is followed by other word
2. generate text that retains these probabilities (that is - start with any word, draw the next one using probablities calculated in step one, use this word as a base for the next draw and so on)
If I recall correctly text presented was generated using three words sequences, but it is just a simple extension of the idea.
Edit: Hm, Chasma Borealis suggests Red Mars was used as the input

I really don't remember, I wrote the code several years ago.