title: How to create a unique alphanumeric id each time and ensure it doesn't exist in my existing list using python?
body: <p>I need to assign a unique name that contains the word 'user' and a certain random numbers to a user. Something like <code>user32944</code>, <code>user80890</code> etc. So I write a program something like this</p>
  <pre><code>import random
  
  user_list = [&quot;user32944&quot;, &quot;user60690&quot;] # essentially this list is what I retrieve from some database
  user_name = &quot;&quot;
  while(True):
      if user_name not in user_list:
          user_name = &quot;user&quot; + str(random.random() * 100000).split(&quot;.&quot;)[0]
          break
  
  print(user_name)
  </code></pre>
  <p>But if I deliberately set the <code>user_name</code> to something that already exists in the list, my program doesn't exit the loop and the program hangs.</p>
  <p>What am I doing wrong?</p>