I have a question. If I generate a random string (alphanumeric with alphabets in capital) in python, how do I ensure that the whole string is not repeated again? Below is my code for randomly generating a string of 6 characters. If a string, say "GU8YZ9" is generated, how do I ensure that "GU8YZ9" is not generated again? Is there any algorithm or in - built function for that? Please help ASAP!
import random, string
num = 6
chars = string.ascii_uppercase + string.digits
''.join(random.choice(chars) for x in range(num))
Aucun commentaire:
Enregistrer un commentaire