Skip to content

Instantly share code, notes, and snippets.

@johnlees
Last active February 12, 2021 12:43
Show Gist options
  • Save johnlees/6398a6c270ad18e2bba6e428c032c711 to your computer and use it in GitHub Desktop.
Save johnlees/6398a6c270ad18e2bba6e428c032c711 to your computer and use it in GitHub Desktop.
Pseudoword generator
import json
import random
import string
# Download from https://github.com/dwyl/english-words/raw/master/words_dictionary.json
with open('words_dictionary.json', 'r') as word_list:
real_words = json.load(word_list)
vowels = ["a", "e", "i", "o", "u"]
trouble = ["q", "x", "y"]
consonants = set(string.ascii_lowercase) - set(vowels) - set(trouble)
# Based on a simple interpretation of https://simple.wikipedia.org/wiki/Syllable
def pseudoword():
while True:
vowel = lambda: random.sample(vowels, 1)
consonant = lambda: random.sample(consonants, 1)
cv = lambda: consonant() + vowel()
cvc = lambda: cv() + consonant()
syllable = lambda: random.sample([vowel, cv, cvc], 1)
word = ""
for i in range(random.randint(1, 3)):
word += "".join(syllable()[0]())
if word not in real_words:
break
return word
print(pseudoword())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment