I am constantly finding myself needing to generate usernames for random accounts I signup for. I used to use the same username for everything, but I've tried to stop doing that since a lot of these accounts are just to try something or to get a freebie, so I don't want a giant paper trail of every account I've signed up for following around usernames I use for more important sites.
I used to use a few different websites to generate a user name, and those worked well, but they weren't quick enough for me. They usually forced me to choose from a number of categories like animals, cars or sports and it would create a unique name based off of my choices. That works well if I wanted a real looking user name, or something I planned on associating my online-self with, but most of the time I just want something quick that fits the necessary requirements set by the website for me to create a user name. These requirements usually include some or all of the following:
- between 6 and 9 characters
- contains at least 1 number and 1 character
This python script does one thing, provides you with a random username with at least 5 characters (one capitalized) selecting from A-Z and 4 numbers (0-9). Now, when I need a quick user name I run this script from the terminal and copy and paste the user name into whatever profile I am filling out.
Here's how it works:
First you need to import the neccessary libraries
import string import random
First we're going to set the first letter of our user name name to be a capital. To do this first we need to set the number of characters we want to be capitalized. In my case I only want the 1 character to be a capital so I'll set it to you 1.
upper_case = 1
Next we need to set a variable that will contain all the possible capital letters that our script will randomly choose from (A-Z).
name_upper_chars = string.ascii_uppercase
upper_name = ''.join(random.choice(name_upper_chars) for y in range(upper_case ))
First we set the number of characters we want to get randomly generated
name_size = 4
name_chars = string.ascii_lowercase
name = ''.join(random.choice(name_chars) for x in range(name_size))
Set the number of numbers we want to be randomly generated and store that in a variable. Then we store all the possible choices we have (0-9) in another variable. Finally, use the random.choice method on the variable digits_chars to randomly select a number from our variable holding all our possible choices.
digits_size = 4 digits_chars = string.digits digits = ''.join(random.choice(digits_chars) for z in range(digits_size))
print uper_name + name + digits