Random code generator
<p>I'd like to have a random code generator, written in PHP, that will generate a mixed case code similar to <a href="http://jsfiddle.net/" rel="nofollow">http://jsfiddle.net/</a><strong>UtKYn</strong></p>

<p>Before I start re-inventing the wheel, perhaps someone can point me in the right direction.</p>

<p>Thanks.</p>

<hr>

<p>UPDATE:</p>

<p>JS fiddle was just an example of the code they generate for each code project.
Mixed case can increase the number of the combinations while keeping it fairly short.</p>

<p>I found the following function. What is the probability of it generating a duplicate? Do i need to add a db query to check for dupes against other codes stored in db?</p>

<pre><code>function rand_string($min = "8", $max = "30") 
{
    $code = NULL;
    for($i=0;$i&lt;$min;$i++) 
    {
        $char = chr(rand(48,122));
        while(!ereg("[a-zA-Z0-9]", $char))
        {
            if($char == $lchar) { continue; }
            $char = chr(rand(48,90));
        }
      $pass .= $char;
      $lchar = $char;
    }
    return $pass;
}
</code></pre>
