markov_text, a Python code which uses a Markov Chain Monte Carlo (MCMC) process to sample an existing text file and create a new text that is randomized, but retains some of the structure of the original one.
The program is given a text file, a suffix length N, and a total text length M. Starting at random point in the text, it selects N consecutive words, which are called the prefix. It then finds every word that immediately follows any occurrence of the prefix in the text, and chooses one randomly as the suffix. The prefix is now modified by removing the first word and appending the suffix. The program stops after M consecutive words have been generated in this way.
The information on this web page is distributed under the MIT license.
markov_text is available in a Python version.
ngrams, a Python code which analyzes a string or text against the observed frequency of ngrams (particular sequences of n letters) in English text.
Original Python version downloaded from "Rosetta Code".