Skip to content

Instantly share code, notes, and snippets.

@junhg0211
Created October 9, 2022 11:40
Show Gist options
  • Save junhg0211/89dd32e06ce0af94cf801398ff2911f8 to your computer and use it in GitHub Desktop.
Save junhg0211/89dd32e06ce0af94cf801398ff2911f8 to your computer and use it in GitHub Desktop.
Word Generator
import random
consonants = ['mv', 'tl', 'ř', 'č', 'š', 'p', 'm', 'n', 's', 'dz', 'z', 'l', 't', 'b'][::-1]
vowels = ['e', 'a', 'u', 'o', 'i']
syllables = ['cvc', 'v', 'cv', 'vc']
def get_zipf(contribution):
while True:
number = random.randint(0, len(contribution)-1)
if random.random() < 1/(number + 1):
return contribution[number]
words = []
def generate_word(syllable):
result = ''
for i in range(syllable):
arrangement = get_zipf(syllables)
for letter in arrangement:
if letter == 'c': result += get_zipf(consonants)
else: result += get_zipf(vowels)
return result
for i in range(20):
words.append(generate_word(1))
print(words)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment