[PYTHON] A function that returns a random name

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

A function that returns a random name
# Function that returns the character code of a string
A simple IDAPython script to name a function
A function that evaluates short-circuits and returns a value other than None that first appeared.
Differentiate a two-variable function
Make a function decorator
A function that easily calculates a listwise removal tree (Python)
Create a PythonBox that outputs with Random after PEPPER Input
I made a LINE BOT that returns parrots with Go
A function that divides iterable into N pieces in Python
Loop through a generator that returns a date iterator in Python
Tornado-Let's create a Web API that easily returns JSON with JSON
[Golang] A program that determines the turn with random numbers
Create a function in Python
Write a kernel density function
How to call a function
Try creating a CRUD function
Let's draw a logistic function
What is a callback function?
A function that measures the processing time of a method in python
A script that returns 0, 1 attached to the first Python prime number