title: Unique code with fixed number of digits
body: <p>In my mysql database I store offers that can be displayed in my PHP web app. Each offer has its unique auto-increment database ID, which I do not want to show to users. However, I need some public unique identifier.</p>
  
  <p><strong>Why I do not want to show real ID</strong></p>
  
  <ul>
  <li>Number of digits can vary and after some time the number could be too long</li>
  <li>If someone subtracted IDs of two selected offers, he would receive number of offers published between those two offers</li>
  </ul>
  
  <p><strong>What I want from public ID</strong></p>
  
  <ul>
  <li>To be unique</li>
  <li>To have fixed number of digits (optimal 5 or 6)</li>
  </ul>
  
  <p><strong>What I know</strong></p>
  
  <ul>
  <li>Maximal duration of active offer is 6 months (It could be longer in the future, but not more then one year)</li>
  </ul>
  
  <p><strong>I was thinking about:</strong></p>
  
  <ul>
  <li>A singular transformation of "real" ID</li>
  <li>A transformation of timestamp</li>
  <li>Generate list of unused numbers, as it is suggested in: <a href="https://stackoverflow.com/questions/15349170/generate-6-digit-unique-number">Generate 6 Digit unique number</a></li>
  </ul>
  
  <p><strong>Questions:</strong></p>
  
  <ol>
  <li>Is the last option the best for you? Or can you suggest any other commonly used method/technique.</li>
  <li>Is it OK to keep table with 900 000 rows for all 6 digits numbers?</li>
  <li>How can I handle situation if (theoretically) my number of active offers exceeds the number of 900 000 (I know that if this happened, point 2 would be irrelevant)</li>
  <li>Is it correct to have more inactive offers with potentially same ID? For example, it could happen that some user would like to refer to his old offer. </li>
  <li>Wouldn't be better to use letters together with digits in order to extend the number of possible combinations?</li>
  </ol>