Link to home
Start Free TrialLog in
Avatar of jblayney
jblayneyFlag for Canada

asked on

create random string

Hello, I have a function which is supposed to create a random 8 character string, it works most of the time, but sometimes it creates a 7 character string.. very weird, please help...

function genRandomString() {
    $length = 8;
    $characters = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';
    $string = "";    
    for ($p = 0; $p < $length; $p++) {
        $string .= $characters[mt_rand(0, strlen($characters))];
    }
    return $string;
}
ASKER CERTIFIED SOLUTION
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial