title: How can I create a unique 7-digit code for an entity?
body: <p>When a user adds a new item in my system, I want to produce a unique non-incrementing pseudo-random 7-digit code for that item.  The number of items created will only number in the thousands (&lt;10,000).</p>
  
  <p>Because it needs to be unique and no two items will have the same information, I could use a hash, but it needs to be a code they can share with other people - hence the 7 digits.</p>
  
  <p>My original thought was just to loop the generation of a random number, check that it wasn't already used, and if it was, rinse and repeat.  I think this is a reasonable if distasteful solution given the low likelihood of collisions.</p>
  
  <p>Responses to <a href="https://stackoverflow.com/questions/616561/how-to-generate-a-unique-4-digit-string">this question</a> suggest generating a list of all unused numbers and shuffling them.  I could probably keep a list like this in a database, but we're talking 10,000,000 entries for something relatively infrequent.</p>
  
  <p>Does anyone have a better way?</p>