note 87750 added to function.rand
| From: | deathshadow60 at hotmail dot com | Date: | Fri, 19 Dec 2008 08:56:03 +0000 |
| Subject: | note 87750 added to function.rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-148346@lists.php.net to get a copy of this message | ||
Some of these random character string functions are just mind boggling the LACK of logic... String
index lookups? Complex 'break' logic? Even simple math sillyness.
$r = chr(rand(0,25)+65);
Yeah, that extra addition is SO neccessary, NOT.
$r=chr(rand(65,90));
better.
Let's see... This would not give an even distribution as it would favor the numbers (which
would make a full third of it), but would probably be faster than what we're seeing so far:
function randString($length) {
$result='';
for (t=0; t<$length; t++) {
switch (rand(0,2)) {
case 0:
$result.=chr(rand(97,122));
break;
case 1:
$result.=chr(rand(65,90));
break;
default:
$result.=chr(rand(48,57));
}
}
return $result;
}
----
Server IP: 64.71.164.2
Probable Submitter: 66.65.224.128
----
Manual Page -- http://www.php.net/manual/en/function.rand.php
Edit -- https://master.php.net/note/edit/87750
Del: integrated -- https://master.php.net/note/delete/87750/integrated
Del: useless -- https://master.php.net/note/delete/87750/useless
Del: bad code -- https://master.php.net/note/delete/87750/bad+code
Del: spam -- https://master.php.net/note/delete/87750/spam
Del: non-english -- https://master.php.net/note/delete/87750/non-english
Del: in docs -- https://master.php.net/note/delete/87750/in+docs
Del: other reasons-- https://master.php.net/note/delete/87750
Reject -- https://master.php.net/note/reject/87750
Search -- https://master.php.net/manage/user-notes.php