title: Python - Why use anything other than uuid4() for unique strings?
body: <p>I see quit a few implementations of unique string generation for things like uploaded image names, session IDs, et al, and many of them employ the usage of hashes like SHA1, or others.</p>
  
  <p>I'm not questioning the legitimacy of using custom methods like this, but rather just the reason. If I want a unique string, I just say this:</p>
  
  <pre><code>&gt;&gt;&gt; import uuid
  &gt;&gt;&gt; uuid.uuid4()
  UUID('07033084-5cfd-4812-90a4-e4d24ffb6e3d')
  </code></pre>
  
  <p>And I'm done with it. I wasn't very trusting before I read up on uuid, so I did this:</p>
  
  <pre><code>&gt;&gt;&gt; import uuid
  &gt;&gt;&gt; s = set()
  &gt;&gt;&gt; for i in range(5000000):  # That's 5 million!
  &gt;&gt;&gt;     s.add(str(uuid.uuid4()))
  ...
  ...
  &gt;&gt;&gt; len(s)
  5000000
  </code></pre>
  
  <p>Not one repeater (I wouldn't expect one now considering the odds are like 1.108e+50, but it's comforting to see it in action). You could even half the odds by just making your string by combining 2 <code>uuid4()</code>s.</p>
  
  <p>So, with that said, why do people spend time on random() and other stuff for unique strings, etc? Is there an important security issue or other regarding uuid?</p>