Skip to content

Instantly share code, notes, and snippets.

@busterb
Created Feb 26, 2014
Embed
What would you like to do?
#!/usr/bin/env python
import random, sys, os
random.seed()
nonword = "\n" # Since we split on whitespace, this can never be a word
w1 = nonword
w2 = nonword
# GENERATE TABLE
table = {}
git_log = os.popen("git log --pretty=oneline --abbrev-commit")
for line in git_log:
for word in line.split()[1:]:
table.setdefault( (w1, w2), [] ).append(word)
w1, w2 = w2, word
table.setdefault( (w1, w2), [] ).append(nonword) # Mark the end of the file
# GENERATE OUTPUT
maxwords = int(random.random() * 50)
(w1, w2) = random.choice(table.keys())
first = True
for i in xrange(maxwords):
newword = random.choice(table[(w1, w2)])
if newword == nonword: sys.exit()
if first:
print(newword.capitalize()),
first = False
else:
print(newword),
w1, w2 = w2, newword
print "Haha"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment