Skip to content

Instantly share code, notes, and snippets.

View donkirkby's full-sized avatar
🐍

Don Kirkby donkirkby

🐍
View GitHub Profile
@donkirkby
donkirkby / gist:5312490
Last active December 15, 2015 19:38 — forked from agiliq/gist:131679
Markov text generator, with bug fix to wrap around from end of source text to the start. Also add a method to generate complete sentences based on the location of periods in the source.
import random
class Markov(object):
def __init__(self, open_file):
self.cache = {}
self.open_file = open_file
self.words = self.file_to_words()
self.word_size = len(self.words)
self.database()