note 26860 added to function.rand
| From: | php-general at lists dot php dot net | Date: | Fri, 15 Nov 2002 03:58:04 +0000 |
| Subject: | note 26860 added to function.rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-39516@lists.php.net to get a copy of this message | ||
This seems quite randomized to me, and useful.
//
//Function - Psuedo-Random ASCII generator for hashing etc
//
srand((double)microtime()*1234567);
function rand_ascii($num) {
for ($i=0;$i<$num;$i++) {
$randnum .= "&#" . rand(33,255) . ";";
}
return $randnum;
}
--------------------------
I tested this 200 times over and over, throwing them into arrays and comparing each array to 199
others. I did this several times and came up with no matches.
Expect to see this type of look to your printed results:
yÍ»¥éØsL/;7õ5µ³ô!S¼uw
ãh)¹ÓÕUziF*ç½P½ýa)dìð©
ëzXU'ÅUαrÖVÛlGl®s=Ñx
Ïwk3è¸Ó3][Ã0LÙ/VzÒÔÚ
--
it isn't the most widly randomized thing, but trimming rand(33,255) to rand(48,57) gives you
anything from 0 - 9, trimming to rand(65,90) gives you anything from A - Z, and rand(97,122)
anything from a - z. (Note, the middle of 'Z' and 'a' are the following
characters, in order: [\]^_`
Enjoy
--
http://www.php.net/manual/en/function.rand.php
http://master.php.net/manage/user-notes.php?action=edit+26860
http://master.php.net/manage/user-notes.php?action=delete+26860
http://master.php.net/manage/user-notes.php?action=reject+26860