How Do I Implement a Name Generator?

I’m creating this game where players can pick their character’s first and last name. When the menu is first loaded up I want names to be randomly generated for the character. If the player doesn’t like the names they can either type in their own or click first name to randomly generate a new first name (the same for last name).

The issue is that I don’t know how to implement this and I would greatly appreciate any suggestions.


from random import shuffle
names = ["Bob","Jon","Frank"]
shuffle(names)

print(names[0])

The above code will give you a random name from the list.

that is how to do it in python but it is not how to do it in the bge.

from random import shuffle
import bge
cont = bge.logic.getCurrentController()
own = cont.owner
names =  ['Bob', ....]
used = []
agents = 5
if agents > len(names):
    print('o no dat is no goodz')

for i in range(agents):
    actor =own.scene.addObject('actor',own,0)
    shuffle(names)
    go=0
    try=0
    while go==0:
        if names(0) not in used:
            actor.name =names(0)
            used.append(names(0))
            go=1
        else:
            if try<len(names):
                shuffle(names)
                try+=1
            else:
                  print('o geeez')
                  go=-1
                  actor.name = 'potato'

why shuffle a list, if you can pick a random entry?


from random import choice
names = ["Bob","Jon","Frank"]

print(choice(names))

anyway…

To create real random names


from random import choice


def name_generator():


    vowels      = ['a','e','i','o','u','y']
    consonants  = ['b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','z']


    name_length = 6
    name        = ''
    
    for i in range(name_length):
        
        characters  = choice(['vowels','consonants'])
        char        = choice(characters)
         
        if not name:
            name += char
        elif name[-1] in consonants:                
            name += choice(vowels)
        elif name[-1] in vowels:
            name += choice(consonants)
        else:
            name += char


    print(name)

You can setup in Logic Bricks but it is quite a lot to do.

Here is a sample implementation, that makes a random choice (1…3). This choice will be mapped to a text value (1->“Red”, 2-> “Green”, 3->“Blue”).

Be aware this does not care if a choice was already picked before. Two consecutive picks can result in the same value.

Attachments


What cotaks said is the “procedural” way of generating names. They are not going to make sense but will be pronounceable. For example: egakilom. or tofuti. Completley random but pronouncable. I implemented this concept into my BGMC 22 game Every Man’s Sky

ok made a .blend that creates front and last name on load, then you can change the front and or last name on the fly

Instead of using the procedural method I had wanted the program to randomly pick from a list of names like what TheDave posted. I tried to change the .blend file that Cotaks created to fit this but I couldn’t figure out how to do it correctly.

Also, instead of changing the first name with the left click and the last name with the right click. I want to be able to just left click on each.

added an other version: https://blenderartists.org/forum/showthread.php?442656-random-name-generator-(front-and-last-name)&p=3268504#post3268504
text is parented to a plane, the plane is the ‘button’.

Thank you very much!