I am trying to generate a random 4 character alphanumeric code. For some reason my script is sometimes generating a 3 character code, though most the time it is doing a 4 character. Thanks for your help!
<?php function randomCode() { $length = 4; $characters = '2345678ABCDEF'; $code= ''; for ($p = 0; $p < $length; $p++) { $code.= $characters[mt_rand(0, strlen($characters))]; } return $code; } echo randomCode($code); ?>