Doc #53207 [Com]: Missing Example for mt_getrandmax
| From: | frozenfire at thefrozenfire dot com | Date: | Fri, 05 Nov 2010 19:43:53 +0000 |
| Subject: | Doc #53207 [Com]: Missing Example for mt_getrandmax | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-5469@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=53207&edit=1
ID: 53207
Comment by: frozenfire at thefrozenfire dot com
Reported by: + at ni-po dot com
Summary: Missing Example for mt_getrandmax
Status: Open
Type: Documentation Problem
Package: Documentation problem
PHP Version: Irrelevant
Block user comment: N
New Comment:
I have added a patch which adds the proposed example to the
mt_getrandmax function. Previously, there was no examples refsect, so
that was added as well.
I included two instance of the output; both with and without parameters
to the function.
Previous Comments:
------------------------------------------------------------------------
[2010-10-30 17:49:53] + at ni-po dot com
Ooops, I'm sorry, the code should be:
// calculate random floating point number
function randomFloat($min = 0, $max = 1) {
return $min + mt_rand() / mt_getrandmax() * ($max - $min);
}
echo randomFloat(0, 1);
Fixed wrong range calculation and use $min / $max instead of $from /
$to.
------------------------------------------------------------------------
[2010-10-30 17:41:18] + at ni-po dot com
Description:
------------
I want to propose an example for mt_getrandmax:
Code:
// calculate random floating point number
function randomFloat($from = 0, $to = 1) {
return $from + mt_rand() / mt_getrandmax() * $to;
}
echo randomFloat(0, 1);
Sample Output:
0.32345942003814
As generating uniform random values in the mathematical sense is the
only application I see for mt_getrandmax I think this should be
included.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=53207&edit=1