title: Create unique random codes - PHP/MySQL
body: <p>I have to create unique codes for each "company" in my database.</p>
  
  <p>The only way I see this to be possible is to create a random number with <code>rand()</code> and then check if the number exists for this "company" in the DB, if it does recreate.</p>
  
  <p>My question is: Is there not a better way to do this - a more efficient way. As if I am creating 10 000 codes and there are already 500 000 in the DB it's going to get progressively slower and slower.</p>
  
  <p>Any ideas or tips on perhaps a better way to do it?</p>
  
  <p>EDIT:</p>
  
  <p>Sorry perhaps I can explain better. The codes will not all be generated at the same time, they can be created once a day/month/year whenever.</p>
  
  <p>Also, I need to be able to define the characters of the codes for example, alpha numberic or numbers only</p>