davedelong / DDMathParser

String → Number
MIT License
854 stars 153 forks source link

random function does not function as documented #158

Closed steve-h closed 4 years ago

steve-h commented 6 years ago

The random function uses drand48:

The drand48() and erand48() functions return values of type double. The full 48 bits of r(n+1) are loaded into the mantissa of the returned value, with the exponent set such that the values produced lie in the interval [0.0, 1.0).

I changed the last line of the procedure like this to get the documented behavior:

       return drand48() * range + lowerBound
//        return (drand48().truncatingRemainder(dividingBy: range)) + lowerBound