In this program, you’ll learn how to how to generate a random alphanumeric String in Python.
To properly understand this Generation of the Random alphanumeric string program, you should have the knowledge of following Python programming topics:
- Python Input, Output and Import
- Python random module
Program to Generate a Random Alphanumeric String
import uuid def my_random_string(string_length=10): """Returns a random string of length string_length.""" # Convert UUID format to a Python string. random = str(uuid.uuid4()) # Make all characters uppercase. random = random.upper() # Remove the UUID '-'. random = random.replace("-","") # Return the random string. return random[0:string_length] print(my_random_string(6)) # For example, D9E50C
Note: we can get a different number and alphabet as this Program generates any random number and alphabet. and numbers will range from 0 – 9 and alphabet will range from A – B, as all alphabet will be capital because we have specified that. The syntax of this random function is:
If you want you can change ‘n’ and get desired no output i.e if you put n=9 the output will be 9 characters.
- Program to Solve Quadratic Equation in Python
- Print Hello world! in Python
- Addition of Two Numbers in Python
- Addition of Two Numbers Given by User in Python
- Program to find the area of Triangle in Python
- Program to Generate a Random Number in Python
Ask your questions and clarify your/others doubts on how to generate a random alphanumeric String in Python by commenting. Python Documentation