Random string generation with upper case letters and digits in Python

Random modules : It refers to the collection of data that can be available in any order. Random modules is used to generate the random strings. It consisting of numbers, characters and punctuation that contain any pattern which we want.

It contain two methods 1.random.choice() , 2.secrets.choice().

when the program has been generated output randomly changed.

Example:

import string

import random

A=5

ran = ‘ ‘.join(random.choices(string.ascii_uppercase + string.digits, k = A))

print(“The randomly generated string is : ” + str(ran))

Output : The randomly generated string is : FD8IG

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top