Created
October 9, 2022 11:40
-
-
Save junhg0211/89dd32e06ce0af94cf801398ff2911f8 to your computer and use it in GitHub Desktop.
Word Generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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