Markov Chain Text Generation

Markov Chain Text Generation

This post includes a standalone (only standard headers, no external libs) ~400 line C++ source file that can analyze text and use an order N Markov chain to randomly generate new text in the same style. In the text generation case, it means that a 2nd order Markov chain would look at the previous 2 words to make the next word. Interestingly, an order 0 Markov chain looks at NO WORDS to generate the next word, so is purely random word generation, with similar word counts (by percentage) as the original text.

Source: blog.demofox.org