Instantly share code, notes, and snippets.

Embed
What would you like to do?
Super simple random name generator.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Inspired by https://stackoverflow.com/a/5732034/293064
"""
import random
input_text = '''
[color]
red
green
blue
yellow
orange
purple
violet
magenta
brown
tan
turquoise
black
white
gray
rose
maroon
charcoal
[adjective]
windy
dusty
sappy
clean
happy
sad
prickly
loud
bright
blinking
burning
hot
firey
freezing
frozen
toasted
spicy
big
small
tiny
old
young
grassy
silly
[noun]
turtle
rabbit
tiger
bear
pug
sloth
cricket
toad
ape
chimp
bat
bird
stallion
horse
hound
camel
salad
castle
palace
cave
beach
forest
desert
atoll
sand
rain
wind
water
trousers
shorts
shirt
pant
sock
dinner
magician
hero
knight
villain
vandal
prince
slouch
goon
violin
delorean
fire
ice
bread
ding
library
dust
sand
plan
home
wand
pond
grass
'''.strip()
_parts = {}
current_index = []
for line in input_text.split('\n'):
line = line.strip()
if len(line) == 0:
continue
if line.startswith('[') and line.endswith(']'):
current_index = []
_parts[line[1:-1]] = current_index
else:
current_index.append(line.strip())
del input_text, current_index, line
def roll():
# parts_keys = _parts.keys()
parts_keys = ['color', 'adjective']
random.shuffle(parts_keys)
name = '-'.join(random.choice(_parts[key]) for key in parts_keys + ['noun'])
return name
if __name__ == '__main__':
import sys
n = 1
if len(sys.argv) > 1 and sys.argv[1].isdigit():
n = int(sys.argv[1])
for i in xrange(n):
print(roll())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment