Total digits are inconsistent
<p>I m using following code to get random hex values. But the output is inconsistent
Sometimes it returns 6 digits sometimes 5 digits</p>

<pre><code>function generateHexValue($length=6) 
{
    $chars = "0123456789abcdef";

    $i = 0;
    $str = "";

    while ($i&lt;$length) {
        $str .= $chars[mt_rand(0,strlen($chars))];
        $i++;
    }

    return $str;    
}

$col=generateHexValue();
echo "&lt;div style='background-color:#".$col."; width:100px; height:100px;'&gt;&lt;/div&gt;";
echo $col."&lt;br/&gt;";
</code></pre>
