note 27891 deleted from function.rand by aidan

From: Date: Sat, 10 Jul 2004 02:34:15 +0000
Subject: note 27891 deleted from function.rand by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-72965@lists.php.net to get a copy of this message
Note Submitter: ---- Further correction for random password function: The comments in entis's code are incorrect for the second and third cases. They should be: // [11,35] => [A,Y] and // [36,61] => [`,y] to conform to what entis's code actually does; and the code would be a little clearer if the third case read Chr($randomNumber + 96 - 35) though why anyone would want to use backtick in a password is beyond me. I'd stick to the original version (by clev) if I wanted to do it this way. There is, after all, nothing wrong with it. Generally I find this approach more readable, though: function RandomPassword( $passwordLength ) { $passwordChars = '0123456789' .'ABCDEFGHIJKLMNOPQRSTUVWXYZ' .'abcdefghijklmnopqrstuvwxyz'; $password = ""; for ($index = 1; $index <= $passwordLength; $index++) { // pick random number $randomNumber = rand(1,strlen($passwordChars)); $password .= substr($passwordChars,$randomNumber-1,1); } return $password; }

« previous php.notes (#72965) next »