title: PHP Random String Generator... not so random
body: <p>I always thought my code generated pretty random strings but I've been pressing F5 for about 10 minutes and I display 10 strings at once and I have had THREE DUPLICATES, UNIBON, ZANOPE and ZOTAXS.</p>
  
  <p>Can anyone explain why this is when I though there code be 26^6 possibilities?</p>
  
  <pre><code>$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  $pass = '';
  for ($i = 0; $i &lt; $len; $i++){
      $pass .= $chars[(rand() % strlen($chars))];
  }
  return $pass;
  </code></pre>
  
  <p>Any advice would be much appreciated.</p>
  
  <p>Thanks</p>
  
  <hr>
  
  <p>Using mt_rand the first duplicate takes on average between 10 and 60 seconds, that seems okay doesn't it?</p>
  
  <pre><code>echo 'start: '.date('H:i:s');
  for ($i = 1; ; $i++) {
      $testarr[]  = passGen(6);
      $new        = passGen(6);
      if (in_array($new,$testarr)){
          echo '&lt;br&gt;end: '.date('H:i:s');
          echo '&lt;br&gt;string: '.$new;
          echo '&lt;br&gt;count: '.count($testarr);
          break;
      }
  }
  </code></pre>