Last modified: 2006-12-11 21:09:59 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T10121, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 8121 - wfRandom() is not between 0 and 1
wfRandom() is not between 0 and 1
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
General/Unknown (Other open bugs)
unspecified
All All
: Normal trivial (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2006-12-02 16:02 UTC by Lejonel
Modified: 2006-12-11 21:09 UTC (History)
0 users

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Lejonel 2006-12-02 16:02:13 UTC
wfRandom returns a value greater than 1 with a probability of ~2^-31 (if
mt_getrandmax == 2^31-1). I don't think that will cause any problems, but a
comment in the code says the value should be between 0 and 1.

Here is a "correct" version of the function:

function wfRandom() {
    # The maximum random value is "only" 2^31-1, so get two random
    # values to reduce the chance of dupes
    $max = mt_getrandmax() + 1;
    $rand = number_format( (mt_rand() * $max + mt_rand())
        / $max / $max, 12, '.', '' );
    return $rand;
}
Comment 1 Antoine "hashar" Musso (WMF) 2006-12-11 21:09:59 UTC
Fixed in r18271

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links