samedi 8 août 2020

Generate better names with no module

I know this could possibly be flagged as opinion based but I created a script that will generate random names with no library. I created a few perimeters that it must follow such as no name should have three vowels or consonants in a row or a name should not have two of the same vowels or consonants in a row because this can damage many names. So the names I get are names but really odd and weird:

mulaku
--------
keorah
--------
oslouv
--------
macaog
--------
oavsut
--------
lnoufi
--------
tkamio
--------
iodecs
--------
ohihto
--------
iufuct
--------
Joskitso

Some of these names just straight up can't be pronounced. "lnoufi"??? Does any one know a couple of ideas towards making my name look and sound more like a name. Here is the code I have so far:

import string
import random
def Gen():
    letters = string.ascii_lowercase[:-4].replace('q','')
    letters = letters.replace('j','')
    passed = False
    while passed == False:
        vowels = 3
        consanants = 3
        consanantCount = 0
        vowelCount = 0
        VowelMany = 0
        VowelManyFinal = None
        ConManyFinal = None
        ConMany = 0
        reps = 1
        name = ''.join(random.choice(letters) for i in range(vowels+consanants))
        name = ''.join(['' if i>reps-1 and e==name[i-reps] else e for i,e in enumerate(name)])
        for letter in name:
            if letter in 'aeiou':
                vowelCount +=1
            else:
                consanantCount +=1
            if letter in 'aeiou':
                VowelMany +=1
                if VowelMany > 2:
                    VowelManyFinal = True
            else:
                VowelMany = 0

            if letter in 'bcdfghjklmnprstv':
                ConMany+=1
                if ConMany > 2:
                    ConManyFinal = True
            else:
                ConMany = 0
        if vowelCount == vowels and consanantCount == consanants and VowelManyFinal != True and ConManyFinal != True:
            passed = True
        else:
            passed = False
            
    return name
for i in range(10):
    print(Gen())
    print('--------')



Aucun commentaire:

Enregistrer un commentaire