php - randomString Function Generates error? -
i writing authentication class in php , when have following function,
private function randomstring($length = 50) { $characters = "1234567890abcdefghijklmnopqrstuvwxyz"; $string = ''; ($p=0; $p < $length; $p++) { $string .= $characters[mt_rand(0, strlen($characters))]; } return $string; }
i following error:
notice: uninitialized string offset: 36
i new creating classes don't know have done wrong here. or there better method of generating random string?
last char index 35, need use strlen(...)-1
:
$string .= $characters[mt_rand(0, strlen($characters) - 1)];
Comments
Post a Comment