I have a PHP function that can generate alpha-numeric string with given length. The function works fine. But the generated string includes digits sometimes, and sometimes it does not include digits. I want that the string must consist of number and alpha every time. Need suggestion for that. Here is the code of the function:
public static function GenerateAlphaNumString($length=0) {
$characterPool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characterPool[rand(0, strlen($characterPool) - 1)];
}
return $randomString;
}
$length < 2.rand()is not really random.