Created
January 5, 2017 23:29
-
-
Save benrules2/033118dc611f4c993f8fbbd16a3e779e to your computer and use it in GitHub Desktop.
Generate message from Markov Chain
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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