note 77716 added to function.rand
| From: | Ishtar at osu1 dot php dot net | Date: | Mon, 10 Sep 2007 13:18:20 +0000 |
| Subject: | note 77716 added to function.rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-130339@lists.php.net to get a copy of this message | ||
A small comment on phpdev-dunnbypauls conclusion that rand() only generates numbers that are a
multiply of 3.
<?php
$n = rand(0,100000); // with MAX_RAND=32768
?>
Since, 100000/32768=3.05 you get multiples of 3. The random integer will be multiplied by 3.05 to
fit between 0 and 100000. rand() works fine, if you don't ask for bigger numbers then RAND_MAX.
----
Server IP: 83.137.20.107
Probable Submitter: 80.60.66.30
----
Manual Page -- http://www.php.net/manual/en/function.rand.php
Edit -- https://master.php.net/note/edit/77716
Del: integrated -- https://master.php.net/note/delete/77716/integrated
Del: useless -- https://master.php.net/note/delete/77716/useless
Del: bad code -- https://master.php.net/note/delete/77716/bad+code
Del: spam -- https://master.php.net/note/delete/77716/spam
Del: non-english -- https://master.php.net/note/delete/77716/non-english
Del: in docs -- https://master.php.net/note/delete/77716/in+docs
Del: other reasons-- https://master.php.net/note/delete/77716
Reject -- https://master.php.net/note/reject/77716
Search -- https://master.php.net/manage/user-notes.php