Skip to content

Instantly share code, notes, and snippets.

@aolkin
Last active April 1, 2024 02:14
Show Gist options
  • Save aolkin/728b46f90c898096c079 to your computer and use it in GitHub Desktop.
Save aolkin/728b46f90c898096c079 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import random, string, sys
FREQUENCIES = {'L': 7253, 'G': 3693, 'P': 3316, 'M': 4761, 'K': 1257, 'A': 14810, 'R': 10977, 'I': 13318, 'F': 4200, 'Y': 3853, 'T': 16587, 'H': 10795, 'C': 4943, 'X': 315, 'J': 188, 'B': 2715, 'V': 2019, 'O': 14003, 'D': 7874, 'Z': 128, 'W': 3819, 'N': 12666, 'U': 5246, 'Q': 205, 'S': 11450, 'E': 21912}
VOWELS = "aeiou"
SINGLES = "aI"
DOUBLES = "lseotfprmcndgb"
ENDS = "etds"
ICKY_BIGRAMS = ("hg","fb","fg","sr","pn","tl")
choices = []
for l, n in FREQUENCIES.items():
for i in range(n):
choices.append(l.lower())
def letter():
return random.choice(choices).lower()
def word():
length = int(random.random() * 9) + 1
if length == 1:
return random.choice(SINGLES)
out = letter()
while len(out) < length:
choice = letter()
if len(out) > 1:
if out[-1] == choice and out[-2] == choice:
continue
if choice in VOWELS and out[-1] in VOWELS and out[-2] in VOWELS:
continue
if len(out) > 2 and (not choice in VOWELS) and \
(not out[-1] in VOWELS) and (not out[-2] in VOWELS) and \
(not out[-3] in VOWELS):
continue
if out[-1] == choice and not choice in DOUBLES:
continue
if (out[-1] + choice) in ICKY_BIGRAMS:
continue
out += choice
if random.random() > 0.5:
return out
else:
return out[:-1] + random.choice(ENDS)
if __name__ == "__main__":
times = 1 if len(sys.argv) < 2 else int(sys.argv[1])
for i in range(times):
print(" ".join(["".join([random.choice(string.ascii_lowercase) for i in range(random.randint(1,9))]) for i in range(10)]).capitalize() + ".")
if times > 1:
print()
for i in range(times):
print(" ".join([word() for i in range(10)]).capitalize() + ".")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment