Skip to content

Instantly share code, notes, and snippets.

@neumond
Created January 10, 2019 17:40
Show Gist options
  • Save neumond/81415723ab9fe2a7cbcb8ac684b0d432 to your computer and use it in GitHub Desktop.
Save neumond/81415723ab9fe2a7cbcb8ac684b0d432 to your computer and use it in GitHub Desktop.
import unicodedata
from random import randint, choice
def getcharset():
hira = [chr(i) for i in range(ord('ぁ'), ord('ゟ') + 1)]
rs = []
for ch in hira:
try:
n = unicodedata.name(ch)
except ValueError:
continue
if 'HIRAGANA LETTER' not in n:
continue
if 'SMALL' in n:
continue
rs.append(ch)
return ''.join(rs)
def transcribe(s):
rs = []
for ch in s:
rs.append(unicodedata.name(ch).rsplit(' ', 1)[1])
return ''.join(rs)
def to_base(n, base):
rs = []
while n > 0:
rs.append(n % base)
n //= base
rs.reverse()
return rs
# n = 123545454
# cs = getcharset()
# name = ''.join(cs[v] for v in to_base(n, len(cs)))
# print(name)
# print(transcribe(name))
def mumble(chars, words=50):
wlens = (1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 5, 5, 6)
rs = []
for _ in range(words):
n = randint(1, len(chars) ** choice(wlens))
word = ''.join(chars[v] for v in to_base(n, len(chars)))
rs.append(transcribe(word))
return ' '.join(rs)
print(mumble(getcharset()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment