title: Efficient unique key generation for database entries
body: <p>I'm currently developing a registration system prototype. It's very simplistic and essentially is just a .NET form which gets written into MongoDB.</p>
  
  <p>What I'm stuck with is an efficient way to generate a unique id/key for each user. These ids must be human friendly so something like a 7 character long alphanumeric string e.g. A1B2C3X.</p>
  
  <p>The solutions I've seen so far just use a simple function to generate a random string and then check the database to see if it is unique (and if not repeat untill you find one that is unique). This of course will become more and more computationally expensive as the number of database entries grows.</p>
  
  <p>My idea is to precompute the unique id set and store that in another database. Then when I need to add a new entry into the user database I can "pop" an id from my id databse (in constant time) and know that it does not already exist in the user database without the need to search it.</p>
  
  <p>I'm sure somebody must have done something like this before. Is there a better way? I don't know why I'm struggling so much with this. Your input is very much appreciated.</p>