note 18393 added to function.srand
| From: | sinister at cyberfrag dot com | Date: | Mon, 21 Jan 2002 16:08:15 +0000 |
| Subject: | note 18393 added to function.srand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-25623@lists.php.net to get a copy of this message | ||
It's pretty easy how he's getting a highly random number. Microtime measures the time
since the Epoch (0:00:00 January 1, 1970 GMT). Microtime() returns a string of 2 parts, the current
microsecond count, a space, and then the time since the Epoch. By using (double), he chops off the
seconds-since-Epoch time, and uses the "current microsecond count" until the next second.
Since time moves constantly, microseconds is the smallest unit a programming language makes use of,
the current microseconds up until the next second will give you a million different numbers, every
second. Now simply multiply the 0.xxxxxx number by 1,000,000 (like back in Jr. High School), and it
will niftily place the 0.xxxxxx number in xxxxxx fashion for your seed.
--
http://www.php.net/manual/en/function.srand.php
http://master.php.net/manage/user-notes.php?action=edit+18393
http://master.php.net/manage/user-notes.php?action=delete+18393
http://master.php.net/manage/user-notes.php?action=reject+18393