note 34873 added to function.rand
| From: | arend at auton dot nl | Date: | Sat, 09 Aug 2003 17:52:36 +0000 |
| Subject: | note 34873 added to function.rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-53749@lists.php.net to get a copy of this message | ||
And yet another variation on the random password generation. It is a variation on the algorithm from
'admin at gwdn dot com' and performs exactly the same function, though it ought to be even
faster since it doesn't have to use regular expression matching.
function randomPassword($len = 8)
{
$pass = '';
$lchar = 0;
$char = 0;
for($i = 0; $i < $len; $i++)
{
while($char == $lchar)
{
$char = rand(48, 109);
if($char > 57) $char += 7;
if($char > 90) $char += 6;
}
$pass .= chr($char);
$lchar = $char;
}
return $pass;
}
Arend jr.
----
Manual Page -- http://www.php.net/manual/en/function.rand.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34873
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34873&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34873&report=yes