Custom captcha displaying wrong numbers
<p>I am creating a custom captcha and it works well, but sometimes it will choose a random number from <code>$rand_keys</code> that is greater than the number of boxes displayed.  How do I fix this?</p>

<pre><code>$color = array("red", "blue", "yellow", "white", "green", "purple", "brown", "orange", "pink", "black");
$random_num_box = mt_rand(3,8);

$numbers=array(0,1,2,3,4,5,6,7,8,9);

$rand_keys = array_rand($numbers, $random_num_box);
$ran_box =  mt_rand(0, $random_num_box);

echo "Random number of boxes:  ".$random_num_box."&lt;br /&gt;&lt;br /&gt;";
echo "&lt;div&gt;";
foreach ($rand_keys as $k=&gt;$v) {
    echo "&lt;div style='width: 20px; height: 20px; border: 1px solid #dcdcdc; margin-right: 2px; display: inline-block; background: ".$color[$numbers[$v]].";'&gt;&lt;/div&gt;";
}
echo "&lt;/div&gt;";

echo "&lt;br /&gt;What is the color of box # ". ($ran_box + 1) ."?";
echo "&lt;br /&gt;Answer:  ".$color[$rand_keys[$ran_box]];
</code></pre>
