Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A Python script to generate pseudo-random text using a Markov Chain.
branch: master
Failed to load latest commit information.
.gitignore Initial commit Update Update

Markov Text Generator

This Python script generates pseudo-random text using a Markov chain model.
The Markov chain encodes the statistical properties of a source text with a user-specified n-gram length.
More details on the algorithm can be found on the following page:

The script can be used with two kind of sources:
1. A text file from which the Markov chain is built.
2. A text file with a pre-generated Markov chain from a previous run.

The generated text can be printed on the console or written to a file, while the Markov chain
can be exported to a file and used later (the source file is no longer needed).

Usage examples:

generate_markov_text -s input_text.txt -l 7 -n 1000 -o output_file.txt -w markov.txt  

Generates 1000 letters using a 7 letter n-gram and writes the Markov chain to "markov.txt".

generate_markov_text -r markov.txt -n 1000 -c  

Reads a pre-generated Markov chain from a file and prints 1000 letters on the console.

Something went wrong with that request. Please try again.