Return to Snippet

Revision: 50833
at September 5, 2011 10:38 by fabienthomas


Initial Code
function randStr($length=6)
{
    $str = "";
    $characters = "abcdefghjkmnpqrstwxyz123456789";
    $maxlength = strlen($characters);
    if ($length > $maxlength) {
      $length = $maxlength;
    }
    $i = 0; 
    while ($i < $length) { 
      $char = substr($characters, mt_rand(0, $maxlength-1), 1);
      if (!strstr($str, $char)) { 
        $str .= $char;
        $i++;
      }

    }
    return $str; 
}

Initial URL

                                

Initial Description
just a random string generator function, usefull in captcha building process for example, or in case of random password needed.

Initial Title
Random AlphaNumeric String

Initial Tags

                                

Initial Language
PHP