note 54534 deleted from function.mt-rand by bjori
| From: | bjori@php.net | Date: | Sun, 16 Apr 2006 12:38:17 +0000 |
| Subject: | note 54534 deleted from function.mt-rand by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-108268@lists.php.net to get a copy of this message | ||
Note Submitter: docey
----
if you want an absolute unique id try this,
md5(microtime().data("r").rand(10000, 32000));
this way its almost impossible to generate the same hash
again since the microtime unixtimestamp, the rfc date and
a random number of 5 digits make the changes of having
the same input to create the hash about 22000 posiblities
per milisecond.
so if you can generete 22000 diffrent hashes per
milisecond you might have a double, else you have to wait
another 128 years orso before the same combination can
be generated.
i have run a test om my pc with the possibilties of
generating the same random and with 5 digits it needed
almost 5min before the same number would come again.
this type of hashing can be fairly safe for genereting a
secure session id to keep track that your still talking to
the same client.
i use this in some websites and the performance is barley
affected, although i find the performance diffrence between
rand and mt_rand almost none. use normal rand when you
can and mt_rand only when speed is a must.
one small note to the documentation team, don't know if
here is the right place to ask, but i might be an idea to
place the php version when a function became supported
next to the function name in the listings, now i have to
check each function to see if i can use it in my php version.
just my 2 eurocents,