In this short tutorial I will show you how to make a random name generator in Python.
If you came here looking for some cool random names visit the online name generators.
The name generator script
Open IDLE which is the Python supplied IDE or editor (Go to the bottom of the post to see, how you get started with Python).
Open a new window from the file menu and write the following name generator script into this window.
def name_generator(): import random color = ["Red","Blue","Black","White"] tool = ["Hammer","Drill","Cutter","Knife"] randomNumber1 = random.randrange(0,len(color)) randomNumber2 = random.randrange(0,len(tool)) name = color[randomNumber1] + " " + tool[randomNumber2] print(name) name_generator() (Be aware that copy-paste from the blog may give syntax errors! A correct indent is an important element Python syntax!)
Save it as name-generator.py. Now you can run the python program by pressing F5.
Name generator walk through
Lets walk through the python script, line by line.
- In the first line we define our name generator function.
- Then we import the random module, so we can call the random function later on.
- In line define 2 arrays (color and tool) and asign values to them
- Then we make 2 random numbers based on the length of our arrays. The randrage() function returns an integer in the range defined by the parameters. As parameters we use 0 and the len() function to count the numbers of words in the arrays.
- In line 7 and 8 we make the final name and print it on the screen.
- Finally we call the name generator function, we have just written.
That’s all it takes to make a simple Python random name generator. When you this basic functionality it’s easy to experiment and develop the random name generator to suit your needs and wishes.
Name generator inspiration
For inspiration visit the name generators where you can find a lot of name generators in several genres. From random names over fantasy and nicknames to band and business names.
Python Beginner guides and tutorials
Python is a free scripting language running on all platforms from Linux to Windows. Python is a relative easy programming language and a name generator is a simple application so it’s a good place to start if you wanna learn some programming.
If you haven’t Python installed at your computer you can download it at Python.org. This name generator script is based on python 3.12, which is the newest stable version at the moment.
Or visit this beginner guide to Python which contains lots of links and resources.