note 79968 added to function.rand
| From: | rok dot kralj at gmail dot com | Date: | Fri, 21 Dec 2007 13:14:51 +0000 |
| Subject: | note 79968 added to function.rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-133845@lists.php.net to get a copy of this message | ||
joebert, your function is terribly wrong.
example: random_float(100,101);
Your function has a 100-times bigger possiblility to return 100 than any other float between 100 and
101.
Correct:
<?php
function random_float ($min,$max) {
return $min+lcg_value()*($max-$min);
}
?>
----
Server IP: 91.185.195.14
Probable Submitter: 89.142.69.158
----
Manual Page -- http://www.php.net/manual/en/function.rand.php
Edit -- https://master.php.net/note/edit/79968
Del: integrated -- https://master.php.net/note/delete/79968/integrated
Del: useless -- https://master.php.net/note/delete/79968/useless
Del: bad code -- https://master.php.net/note/delete/79968/bad+code
Del: spam -- https://master.php.net/note/delete/79968/spam
Del: non-english -- https://master.php.net/note/delete/79968/non-english
Del: in docs -- https://master.php.net/note/delete/79968/in+docs
Del: other reasons-- https://master.php.net/note/delete/79968
Reject -- https://master.php.net/note/reject/79968
Search -- https://master.php.net/manage/user-notes.php