Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
README.rst Tweaking reST for github Dec 28, 2010
shakespeare_sonnet.txt Markov poem generator Dec 28, 2010 Markov poem generator Dec 28, 2010


Markov Text Generator

This is a simple Markov text generator that has been customized to generate poem like output using sonnets written by Shakespeare [1] as the source material. Inspired by this article from Coding Horror [2], and loosely based on the code from the Usware Blog [3].

Some of the changes I made were to consider line counts instead of word counts for termination and a reseeder to continue word generation if a matching key could not be found for the next state. In addition I emit some statistics about the database constructed such as the number of key entries and the mean and standard deviation of the number of possible words generated by each key.

This is written and tested in Python 2.6.1, no extra batteries required.

  1. Shakespeare. Shakespeare's Sonnets. [Online]. Available:
  1. Atwood. (2008, Jun.). Markvov and You. [Online]. Available:
[3]Shabda. (2009, Jun.). Generating pseudo random text with Markov chains using Python. [Online]. Available: