title: Generating a unique ID in Javascript
body: <p>I want to implement a saving system similar to <a href="http://imgur.com/" rel="nofollow">Imgur</a> where if a user presses a button a unique 5 character value is returned. Here is what I have so far:</p>
  
  <p>The database backend uses auto-incrementing ID's starting at <code>5308416</code>. I use a modified Radix function (see below) to convert these numerical ID's into characters. I use a reverse function to lookup character ID's back to numerical database ID's.</p>
  
  <pre><code>function genID (value)
  {
      var alphabet = "23456789BCDFGHJKLMNPRSTVWXYZbcdfghjkmnpqrstvwxyz";
  
      var result = "";
      var length = alphabet.length;
  
      while (value &gt; 0)
      {
          result = alphabet[value % length] + result;
          value  = Math.floor (value / length);
      }
  
      return result;
  }
  </code></pre>
  
  <p>The problem is that these generated ID's are very much predictable. My question is, how can I make the generated ID's seem random but still unique (so I can look them up in the database as numbers). I was thinking of using some encryption algorithm but not sure where to start. Any help or suggestions would be appreciated (maybe there is a better way of doing this also).</p>