Doc->Req #53207 [Opn->Asn]: Missing Example for mt_getrandmax

From: Date: Fri, 05 Nov 2010 23:04:20 +0000
Subject: Doc->Req #53207 [Opn->Asn]: Missing Example for mt_getrandmax
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-5471@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 Updated by: frozenfire@php.net Reported by: + at ni-po dot com Summary: Missing Example for mt_getrandmax -Status: Open +Status: Assigned -Type: Documentation Problem +Type: Feature/Change Request Package: Documentation problem PHP Version: Irrelevant -Assigned To: +Assigned To: frozenfire Block user comment: N Previous Comments: ------------------------------------------------------------------------ [2010-11-05 20:43:51] frozenfire at thefrozenfire dot com 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. ------------------------------------------------------------------------ [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

« previous php.doc.bugs (#5471) next »