title: Whats the best way to generate large amounts of unique promo codes?
body: <p>I am trying to create promo codes in large batches (with php/mysql).</p>
  
  <p>Currently my code looks something like this:</p>
  
  <pre><code>$CurrentCodesInMyDB = "asdfasdf,asdfsdfx"; // this is a giant comma delimited string of the current promo codes in the database.
  $PromoCodes = "";
  for($i=0;$i&lt;=30000;$i++)
  {
      $NewCode = GetNewCode($PromoCodes, $CurrentCodesInMyDB );
      $PromoCodes .= $NewCode . ","; //this string gets used to allow them to download a txt file
      //insert $newcode into database here
  }
  
  function GetNewCode($CurrentList, $ExistingList)
  {
      $NewPromo = GetRandomString();
       if(strpos($CurrentList, $NewPromo) === false &amp;&amp; strpos($ExistingList, $NewPromo) === false)
       {
            return $NewPromo; 
       }  
       else
       {
            return GetNewCode($CurrentList, $ExistingList);   
       }
  }
  
  function GetRandomString()
  {
       return "xc34cv87"; //some random 8 character alphanumeric string
  }
  </code></pre>
  
  <p>When I do batches in 10k, it seems to be ok. But the client would like to be able to generate 30k at a time. When I bump the loop up to 30k, I've been having issues. Are there any obvious performance tweaks that I could make or maybe a different way I could do this? </p>