Skip to content

Instantly share code, notes, and snippets.

@benrules2
Created January 5, 2017 23:29
Show Gist options
  • Select an option

  • Save benrules2/033118dc611f4c993f8fbbd16a3e779e to your computer and use it in GitHub Desktop.

Select an option

Save benrules2/033118dc611f4c993f8fbbd16a3e779e to your computer and use it in GitHub Desktop.
Generate message from Markov Chain
def generate_message(chain, count = 100):
word1 = random.choice(list(chain.keys()))
message = word1.capitalize()
while len(message.split(' ')) < count:
word2 = random.choice(chain[word1])
word1 = word2
message += ' ' + word2
return message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment