Doc #53207 [Com]: Missing Example for mt_getrandmax

From: Date: Sat, 30 Oct 2010 15:49: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-5447@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: + at ni-po 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: 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. Previous Comments: ------------------------------------------------------------------------ [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 (#5447) next »