8280550: SplittableRandom#nextDouble(double,double) can return result >= bound

Reviewed-by: jlaskey, psandoz
This commit is contained in:
Joe Darcy 2022-01-26 17:25:30 +00:00
parent a5a11f14b9
commit 0c42e43f77
2 changed files with 54 additions and 2 deletions

View file

@ -645,7 +645,7 @@ public class RandomSupport {
if (origin < bound) {
r = r * (bound - origin) + origin;
if (r >= bound) // may need to correct a rounding problem
r = Double.longBitsToDouble(Double.doubleToLongBits(bound) - 1);
r = Math.nextAfter(r, origin);
}
return r;
}
@ -677,7 +677,7 @@ public class RandomSupport {
double r = rng.nextDouble();
r = r * bound;
if (r >= bound) // may need to correct a rounding problem
r = Double.longBitsToDouble(Double.doubleToLongBits(bound) - 1);
r = Math.nextDown(r);
return r;
}