Every time, same person, how many digits ? Explain more.... EDIT: Without further details, I don't know if this helps ? <?php function genRandomString($length) { $characters = "0123456789"; for ($p = 0; $p < $length; $p++) { $string .= $characters[mt_rand(0, strlen($characters))]; } return $string; } $string = genRandomString(5); // Not more then 5 digits echo $string; ?> PHP: Just <?php echo $string; ?> where you want it to appear