Random string

Generates a random string

Snippet information

Author:
Jonas John

License:
Public Domain

Language:
PHP

Created:
03/28/2006

Updated:
03/28/2006

Tags:
,


function RandomString($len){
    $randstr = '';
    srand((double)microtime()*1000000);
    for($i=0;$i<$len;$i++){
        $n = rand(48,120);
        while (($n >= 58 && $n <= 64) || ($n >= 91 && $n <= 96)){
            $n = rand(48,120);
        }
        $randstr .= chr($n);
    }
    return $randstr;
}


Found a bug? Or do you have a better solution for this?
Feel free to leave a message:

Add a comment


Leave a comment