note 58318 deleted from function.mt-rand by bjori
| From: | bjori@php.net | Date: | Sun, 16 Apr 2006 12:40:31 +0000 |
| Subject: | note 58318 deleted from function.mt-rand by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-108269@lists.php.net to get a copy of this message | ||
Note Submitter: appelNOSPAM at nr78 dot net
----
Phil's code (07-Oct-2005 03:13) + minor improvements in a function (no rocket science):
<?php
function gen_passw($len = 8)
{
// define ASCII ranges...
// See http://www.keller.com/html-quickref/latin1.html
$ranges = array
(
1 => array(97, 122), // a-z (lowercase)
2 => array(65, 90), // A-Z (uppercase)
3 => array(48, 57) // 0-9 (numeral)
);
$passw = "";
for ($i=0; $i<$len; $i++)
{
$r = mt_rand(1,count($ranges));
$passw .= chr(mt_rand($ranges[$r][0], $ranges[$r][1]));
}
return $passw;
}
echo gen_passw(6);
?>