How to Create a Random Name Generator in Python

In this tutorial, we will program 'How to Create a Random Name Generator in Python'. We will learn how to generate a random name. The main goal here is to create a program that will provide a unique randomized name. I will provide a sample program to demonstrate the actual coding of this tutorial.

This topic is very easy to understand; just follow the instructions I provide, and you can also do it yourself with ease. The program I will show you covers the basics of programming for generating a random name. I will do my best to provide you with the easiest method of finding the actual age. So, let's start with the coding.

Getting Started:

First you will have to download & install the Python IDLE's, here's the link for the Integrated Development And Learning Environment for Python

Creating Main Function

This is the main function of the application. The following code will display a simple GUI in terminal console that will display program. To do this, simply copy and paste these blocks of code into the IDLE text editor.
  1. import random
  3. ret = False
  5. first_names = ['Ada', 'Bela', 'Cade', 'Dax', 'Eva', 'Fynn', 'Gia', 'Hugo', 'Ivy', 'Jax']
  6. last_names = ['Smith', 'Johnson', 'Williams', 'Jones', 'Brown', 'Davis', 'Miller', 'Wilson', 'Moore', 'Taylor']
  8. def generate_random_name():
  9. first_name = random.choice(first_names)
  10. last_name = random.choice(last_names)
  11. return f"{first_name} {last_name}"
  14. while True:
  17. print("\n==================== Random Name Generator ==================== \n\n")
  20. random_name = generate_random_name()
  21. input("Press Enter to generate a random name: ")
  22. print("\n")
  23. print("Random name:", random_name)
  24. print("\n")
  25. opt = input("Do you want to try again?(yes/no): ")
  27. if opt.lower() == 'yes':
  28. ret=False
  29. elif opt.lower() == 'no':
  30. ret=True
  31. print("Exiting program....")
  33. else:
  34. print("Please enter yes/no:")
  35. break
  37. if ret == False:
  38. continue

This Python script generates random names by combining a first name randomly chosen from a list of first names and a last name randomly chosen from a list of last names. It prompts the user to press Enter to generate a random name and then displays the generated name. The user can choose to try again or exit the program.


The How to Create a Random Name Generator in Python source code that I provide can be download below. Please kindly click the download button.

There you have it we successfully created How to Create a Random Name Generator in Python. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!

More Tutorials for Python Language

Python Tutorials

Add new comment