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

From: Date: Fri, 05 Nov 2010 23:49:39 +0000
Subject: Req #53207 [Asn->Csd]: Missing Example for mt_getrandmax
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-5473@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: Assigned +Status: Closed Type: Feature/Change Request Package: Documentation problem PHP Version: Irrelevant Assigned To: frozenfire Block user comment: N New Comment: This bug has been fixed in the documentation's XML sources. Since the online and downloadable versions of the documentation need some time to get updated, we would like to ask you to be a bit patient. Thank you for the report, and for helping us make our documentation better. Previous Comments: ------------------------------------------------------------------------ [2010-11-06 00:47:07] frozenfire@php.net Automatic comment from SVN on behalf of frozenfire Revision: http://svn.php.net/viewvc/?view=revision&revision=305119 Log: Added an example to the Math extension's mt_getrandmax function, as per bug #53207. ------------------------------------------------------------------------ [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 (#5473) next »