Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Generate random non-realistic names in Python
import string
import random
vowels = 'aeiou'
consonants = 'bcdfghijklmnpqrstvwxz'
def get_letter(last_letter=None):
# Check if last letter generated was a consonant
if last_letter:
last_letter = ''.join(last_letter)
last_letter_was_consonant = last_letter in consonants
last_letter_was_consonant = False
# If last letter was a vowel, make it 50% chance to generate a consonant
if not last_letter_was_consonant and bool(random.randint(0, 1)):
last_was_consonant = True
yield random.choice(consonants)
last_was_consonant = False
yield random.choice(vowels)
def generate_word(length, spread=0):
word = list()
for i in range(length + random.randint(1, spread)):
return ''.join(word).capitalize()
if __name__ == '__main__':
print('Generating 10 random names:')
for i in range(10):
print(generate_word(length=5, spread=3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment