php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #53207 Missing Example for mt_getrandmax
Submitted: 2010-10-30 17:41 UTC Modified: 2010-11-06 00:49 UTC
From: + at ni-po dot com Assigned: frozenfire (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: + at ni-po dot com
New email:
PHP Version: OS:

 

 [2010-10-30 17:41 UTC] + 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.


Patches

mt_getrandmax-add-example (last revision 2010-11-05 19:51 UTC by frozenfire at thefrozenfire dot com)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-30 17:49 UTC] + 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-11-05 20:43 UTC] 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-11-06 00:04 UTC] frozenfire@php.net
-Status: Open +Status: Assigned -Type: Documentation Problem +Type: Feature/Change Request -Assigned To: +Assigned To: frozenfire
 [2010-11-06 00:47 UTC] 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-06 00:49 UTC] frozenfire@php.net
-Status: Assigned +Status: Closed
 [2010-11-06 00:49 UTC] frozenfire@php.net
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.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC