title: Randomly generated string - no duplication
body: <p>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 &quot;GU8YZ9&quot; is generated, how do I ensure that &quot;GU8YZ9&quot; is not generated again? Is there any algorithm or in-built function for that?</p>
  <pre><code>import random, string
  
  num = 6
  
  chars = string.ascii_uppercase + string.digits
  ''.join(random.choice(chars) for x in range(num))
  </code></pre>