title: Which one is more secure to use? uuid, binascii.hexlify(os.urandom()) or random.SystemRandom()?
body: <p>I want to create unique <code>&lt;client-key&gt;</code> and <code>&lt;client-secret&gt;</code> for the users who registers themselves for the service.</p>
  
  <p>So, I was searching for the same and came up with these options:</p>
  
  <ul>
  <li><a href="https://docs.python.org/2/library/uuid.html#uuid.UUID" rel="noreferrer"><strong>uuid</strong></a></li>
  <li><strong>binascii.hexlify(os.urandom(x))</strong></li>
  <li><a href="https://docs.python.org/2/library/random.html?highlight=random.systemrandom#random.SystemRandom" rel="noreferrer"><strong>random.SystemRandom()</strong></a><br>
  <br />  </li>
  </ul>
  
  <p>It's a silly question but I want to know that which implementation is more secure to use (with proper explanation)? Why? And what are the advantages of using it over others?</p>
  
  <blockquote>
    <p><strong>Note:</strong></p>
    
    <p>AFAIK, <strong><code>random.SystemRandom()</code></strong> uses <strong><code>os.urandom(x)</code></strong>. So comparison is mainly between <strong><code>uuid</code></strong> and <strong><code>random.SystemRandom()</code></strong>.</p>
  </blockquote>
  
  <p>Here's what I've tried so far:</p>
  
  <p>1)</p>
  
  <pre><code>import random
  temp = random.SystemRandom()
  random_seq = ''.join(temp.choice(CHARACTER_SET) for x in range(x))
  &gt;&gt;&gt; 'wkdnP3EWxtEQWnB5XhqgNOr5RKL533vO7A40hsin'
  </code></pre>
  
  <p>2)</p>
  
  <pre><code>import uuid
  str(uuid.uuid4())
  &gt;&gt;&gt; 'f26155d6-fa3d-4206-8e48-afe15f26048b'
  </code></pre>
  
  <p>I'm not sure about the solution. So, any help would be appreciated.</p>
  
  <p><br/>
  <strong>P.S.</strong>
  It'd be great if any solution is available for both Python 2.x and 3.x.</p>