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?
import random, string
num = 6
chars = string.ascii_uppercase + string.digits
''.join(random.choice(chars) for x in range(num))