Skip to content
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


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:
You can’t perform that action at this time.