note 73429 deleted from function.rand by felipe
| From: | felipe@php.net | Date: | Sun, 30 Dec 2007 18:45:25 +0000 |
| Subject: | note 73429 deleted from function.rand by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-134448@lists.php.net to get a copy of this message | ||
Note Submitter: Niels
----
The example from "relsqui at armory dot com" is wrong. It talks about bit operations and
uses "&", but is actually an example of using modulus and should use "%".
The idea is that "rand()%(x+1)" is faster than "rand(0,x)". I agree, it is. But
not a lot.
Here's the fastest function I can think of for making pseudo-unique, valid IDs for HTML tags,
in which the first character can't be a number:
function makeID() {
$s="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
return $s{rand()%52}.$s{rand()%62}.(repeat ad libitum).$s{rand()%62};
}