Page MenuHomePhabricator

wfRandom() is not between 0 and 1
Closed, ResolvedPublic

Description

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() {

  1. The maximum random value is "only" 2^31-1, so get two random
  2. values to reduce the chance of dupes $max = mt_getrandmax() + 1; $rand = number_format( (mt_rand() * $max + mt_rand()) / $max / $max, 12, '.', '' ); return $rand;

}


Version: unspecified
Severity: trivial

Details

Reference
bz8121

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 9:28 PM
bzimport set Reference to bz8121.
bzimport added a subscriber: Unknown Object (MLST).