I'm trying to make some random string in PHP with 5 letters/numbers. It's working fine but sometimes I get a shorter string.
$characterset='ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
$count=0;
$lenght=strlen($characterset);
$i=5; #number of characters
while($count < $i){
$num=rand(1,$lenght);
$letter=substr($characterset, $num, 1);
$string.=$letter;
$count++;
}
And strlen($string) is sometimes 4 (checked 100 records, 85 was 4 characters)