title: Get 10000+ unique random numbers (performance)
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/693880/create-random-number-sequence-with-no-repeats">Create Random Number Sequence with No Repeats</a>  </p>
  </blockquote>
  
  
  
  <p>I'd like to write an URL shortener that only uses numbers as short string.</p>
  
  <p>I don't want to count up, I want the next new number to be random (or pseudo random).</p>
  
  <p>At first thought algorithm would then look like this (pseudo code):</p>
  
  <pre><code>do 
  {
   number = random(0,10000)
  }
  while (datastore.contains(number))
  
  datastore.store(number, url)
  </code></pre>
  
  <p>The problem with this implementation is: As the datastore contains more numbers, the more likely it is that the loop will be executed multiple times. The performance will decrease over time.</p>
  
  <p>Isn't there a better way to get a random number that is not already in use?</p>