Python Randomized Name Generator
May 17, 2021
After dropping of the face off the Earth to complete a semester of school, I am back home for a summer internship. I now have more time to work on my various projects and to make write-ups about them. Over the last semester I played Dungeons and Dragons with a group of friends every Tuesday. It helped to keep me sane and social during the age of the Coronavirus. I was the Dungeon Master for each session, so I was responsible for providing a world for the players to live in.
With the heavy amount of improv that I had to use each session, I made a few different tools in order to lighten the load. One such tool is a Python script that randomly generates names based on several inputs—no more awkward pauses after the players ask for the name of a character that I didn’t prepare a name for in advance! The project was also a great excuse to become familiar with Tkinter.
Two files are used for the name generator, the first is a dictionary that stores forenames and surnames based on gender and race. I also added in a system where forenames could be assembled out of syllables.
forenames = {
'male' : {
'dwarf' : {
'syl_based' : False,
'name' : ['Adrik','Agnar','Alberich','Alvar','Amund','Arne','Arvid']
}
},
'female' : {
'orc' : {
'syl_based' : True,
'first_syl' : ['Gree','Tho','Ze','Na','Mu','Ny','Azo','Bo'],
'second_syl' : ['dda','ga','la','lla','olga','ragg','rall']
}
}
}
surnames = {
'dwarf' : ['Agnarsson','Ahlberg','Alfson','Alvarsson','Amundsson','Arneson','Arvidsson'],
'orc' : ['Bone Breaker','Wet Blade','Steel Skull','Black Axe','Spiked Fist','Bloody Hand', 'Broken Tooth']
}
The above code is a heavily pared down version of the dictionary. As you can see, dwarven forenames aren’t syllable based and are pulled from a singular list. Orc forenames, however, are broken down into two syllables. An example dwarven name would be Adrik Ahlberg. An example orc name would be Greega Bone Breaker.
The second file used for the name generator takes care of the logic and interface (as seen above). This entire project can be found on my GitHub here. I’m pretty happy with how things turn out. The program is easily adapted to additional races or even genders (I plan to add a neutral option personally). Every time ‘Get Names’ is pressed, five new names are generated based on the user input.
As I previously mentioned, this was my first foray into using Tkinter and I’m impressed with what it can do. One of the first programming languages I learned was Visual Basic, so I really appreciate how easily you can use it to make interfaces. This project also marked my first-time using classes in Python. I actually had everything working without classes and then decided to redo it all so that I could gain experience with them.
Since I’ve been home, I’ve been working on my XZ550 and I am very excited to see where that project goes within the next couple of weeks. I also have been spending around an hour each day working on Japanese since the new year started. I’ve got a lot going on right now and I am looking forward to keeping this website updated!
~ JHE