python
import random
def natural(n, f=0):
"""Returns a natural number"""
if n < f:
return f
else:
return int(round(n))
def nrg(mu, sigma=1.2, f=0, t=None):
"""Returns a Gaussian distribution as a natural number"""
num = natural(random.SystemRandom().gauss(mu, sigma), f)
if (t is not None) and (num > t):
return t
else:
return num
def rchp(seq, i=1):
"""Returns a randomly chosen list from the list"""
return [random.SystemRandom().choice(list(seq)) for n in range(i)]
def uwords(fword, lword):
"""Unicode continuous characters"""
return {chr( n ) for n in range( ord( str(fword) ), ord( str(lword) ), +1 )}
class wset:
"""Hiragana and Katakana character constants"""
hira = uwords("Ah", "Hmm") | {"ゝ", "ゞ"}
kata = uwords("A", "ヾ") - {"・", "KA", "Month"}
thira = hira - {"Ah", "I", "U", "Eh", "Mm", "Tsu", "Ya", "Shu", "Yo", "ゝ", "ゞ", "ゎ", "-", "Hmm"}
tkata = kata - {"A", "I", "U", "E", "Oh", "Tsu", "Turbocharger", "Yu", "Yo", "ヽ", "ヾ", "ヮ", "-", "Down"}
dhira = thira | {"Kya", "Kyu", "Kyo", "Gya", "Gyu", "Gyo", "Shah", "Shu", "Sho", "See you", "Ju", "Jo", "Cha", "Chu", "Cho", "Nya", "Nyu", "Nyo", "Hyah", "Hyu", "Hyo", "Mya", "Myu", "Myo", "Rya", "Ryu", "Ryo","ゝ", "ゞ", "-", "Hmm"}
dkata = tkata | {"Ca", "Kyu", "Kyo", "Ga", "Gyu", "Gyo", "Sha", "Shu", "Show", "Ja", "Ju", "Jo", "Nya", "New", "Nyo", "Mya", "Mu", "Myo", "Hya", "Huh", "Hyo", "Cha", "Chu", "Cho", "Lya", "Ryu", "Ryo", "Va", "Vi", "Ve", "-", "Down"}
def rname(segment=2.4, namerange=5.3, hiragana=wset.dhira, katakana=wset.dkata, sep=" = "):
"""Returns a random name (beyond human imagination)"""
rsam = random.SystemRandom().sample
rint = random.randint
segs = []
namerange -= 1
for n in range(nrg(segment, 0.5, 1)):
choicer = rint(0, 100)
if choicer <= 10:
l = rchp(wset.thira,1) + rchp(hiragana, nrg(namerange))
else:
l = rchp(wset.tkata,1) + rchp(katakana, nrg(namerange))
segs.append(''.join(l))
return sep.join(segs)
print(rname())
Random numbers are good! A long time ago, I wrote a function that returns a random name, so I posted it. If you have trouble generating a unique name that humans can't think of, try using it.
Recommended Posts