note 19541 added to function.mt-rand
| From: | demogracia at metropoliglobal dot com | Date: | Sat, 02 Mar 2002 17:38:23 +0000 |
| Subject: | note 19541 added to function.mt-rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-27264@lists.php.net to get a copy of this message | ||
//
// Generates a random string with the specified length
// Chars are chosen from the provided [optional] list
//
function simpleRandString($length=16, $list="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"){
mt_srand((double)microtime()*1000000);
$newstring="";
if($length>0){
while(strlen($newstring)<$length){
$newstring.=$list[mt_rand(0, strlen($list)-1)];
}
}
return $newstring;
}
//
// Generates a random string with the specified length
// Includes: a-z, A-Z y 0-9
//
function randString($length=16){
mt_srand((double)microtime()*1000000);
$newstring="";
if($length>0){
while(strlen($newstring)<$length){
switch(mt_rand(1,3)){
case 1: $newstring.=chr(mt_rand(48,57)); break; // 0-9
case 2: $newstring.=chr(mt_rand(65,90)); break; // A-Z
case 3: $newstring.=chr(mt_rand(97,122)); break; // a-z
}
}
}
return $newstring;
}
--
http://www.php.net/manual/en/function.mt-rand.php
http://master.php.net/manage/user-notes.php?action=edit+19541
http://master.php.net/manage/user-notes.php?action=delete+19541
http://master.php.net/manage/user-notes.php?action=reject+19541