Skip to content

Instantly share code, notes, and snippets.

@cmacrander
Created November 3, 2015 23:47
Show Gist options
  • Save cmacrander/bf864ff724f91bbe88d4 to your computer and use it in GitHub Desktop.
Save cmacrander/bf864ff724f91bbe88d4 to your computer and use it in GitHub Desktop.
Friendly random phrase generator
import random
foods = [
'onion',
'carrot',
'pear',
'bean',
'corn',
'bread',
'apple',
'banana',
'fig',
'grape',
'lemon',
'lime',
'orange',
'peach',
'plum',
]
adjectives = [
'tall',
'short',
'up',
'down',
'fancy',
'busy',
'loud',
'crazy',
'kind',
'nice',
'real',
'speedy',
'handy',
'active',
'alert',
'bold',
'brave',
'bright',
'calm',
'clever',
'cool',
'free',
'grand',
'great',
'happy',
'jolly',
'lucky',
'spicy',
'sunny',
'super',
'wise',
]
animals = [
'bat',
'bear',
'bird',
'cat',
'cow',
'deer',
'dog',
'dove',
'dragon',
'duck',
'eagle',
'fish',
'fox',
'frog',
'goose',
'lion',
'mouse',
'owl',
'pig',
'rat',
'seal',
'shark',
'sheep',
'snake',
'spider',
'tiger',
'turkey',
'viper',
'whale',
'wolf',
]
colors = [
'blue',
'bronze',
'fire',
'forest',
'gold',
'gray',
'green',
'navy',
'purple',
'red',
'silver',
'sky',
'yellow',
'neon',
]
def generate_phrase(n=2):
"""Randomly generate a simple memorable phrase.
Args:
n: int, number of words in the phrase, default 2, max 4.
"""
if n not in range(1, 5):
raise Exception("Invalid number of words for phrase: {}.".format(n))
lists = [foods, animals, colors, adjectives]
return ' '.join([random.choice(l) for l in random.sample(lists, n)])
def print_many(m, n):
"""Print m phrases, each of length n."""
print '\n'.join([generate_phrase(n) for x in range(m)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment