bug
bug copied to clipboard
scala.util.Random.between(minInclusive, maxExclusive) overflow bug.
Reproduction steps
println( new scala.util.Random().between(Double.MinValue, Double.MaxValue) ) // always prints: 1.7976931348623155E308
See this Scastie.
Problem
One would expect a truly, full spectrum random number from the interval [Double.MinValue Double.MaxValue) instead this code always returns 1.7976931348623155E308.
FTR, there is a correct implementation of nextDouble(origin, bound) in the following Scala.js PR:
https://github.com/scala-js/scala-js/pull/5142
It corresponds to what su.Random calls between. A fix could be taken from there.
Happy Pi Day!
Happy Pi Day!
It sure is! Also wanted to tell you @som-snytt that we miss you in Discord land. So glad you're still going strong here, though!
obviously always returning 1.7976931348623155E308 is undesirable and we should do better
but that said, I'm not sure how meaningful it is to ask for a random floating point number over such a wide range — IEEE 754 gets weird once huge numbers are involved, the numbers that are even representable are farther and farther apart from each other. I'm not sure what "truly, full spectrum" even means in this context. (I would imagine there's literature on this...?)
regardless, it seems that a PR porting what Scala.js did would be welcome
If there's no hurry, I'm willing to take the assignment. It took over a year last time. This time, how about maybe a month?