public
Created

  • Download Gist
names_generator.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
from random import choice
 
MALE_NAMES_FILE = 'dist.male.first'
FEMALE_NAMES_FILE = 'dist.female.first'
LAST_NAMES_FILE = 'dist.all.last'
 
if __name__ == '__main__':
MALE_NAMES = list(line.split()[0] for line in open(MALE_NAMES_FILE))
FEMALE_NAMES = list(line.split()[0] for line in open(FEMALE_NAMES_FILE))
LAST_NAMES = list(line.split()[0] for line in open(LAST_NAMES_FILE))
 
randbool = lambda: choice((True, False))
randgender = lambda: choice((MALE_NAMES, FEMALE_NAMES))
 
for _ in range(100):
fullname = []
# gender for this name
GENDER_NAMES = randgender()
# choose first name
fullname.append(choice(GENDER_NAMES))
# maybe choose second name
if randbool():
fullname.append(choice(GENDER_NAMES))
# choose last name
fullname.append(choice(LAST_NAMES))
# maybe choose second last name
if randbool():
fullname.append(choice(LAST_NAMES))
 
# print capitalized
print ' '.join(map(str.capitalize, fullname))

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.