Skip to content

Commit

Permalink
8281183: RandomGenerator:NextDouble() default behavior partially fixe…
Browse files Browse the repository at this point in the history
…d by JDK-8280950

Reviewed-by: phh
Backport-of: 77b0240d44fd356711d75bc241e198f6f89ada8f
  • Loading branch information
GoeLin committed Nov 3, 2022
1 parent 182173a commit 3b40d21
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
Expand Up @@ -547,7 +547,7 @@ public double nextDouble(double bound) {
throw new IllegalArgumentException(BAD_BOUND);
double result = (mix64(nextSeed()) >>> 11) * DOUBLE_UNIT * bound;
return (result < bound) ? result : // correct for rounding
Math.nextDown(result);
Math.nextDown(bound);
}

/**
Expand Down
Expand Up @@ -414,7 +414,7 @@ public double nextDouble(double bound) {
throw new IllegalArgumentException(BAD_BOUND);
double result = (mix64(nextSeed()) >>> 11) * DOUBLE_UNIT * bound;
return (result < bound) ? result : // correct for rounding
Math.nextDown(result);
Math.nextDown(bound);
}

/**
Expand Down
9 changes: 6 additions & 3 deletions test/jdk/java/util/Random/RandomNextDoubleBoundary.java
Expand Up @@ -24,7 +24,7 @@
/*
* @test
* @summary Verify nextDouble stays within range
* @bug 8280550 8280950
* @bug 8280550 8280950 8281183
*/

import java.util.SplittableRandom;
Expand Down Expand Up @@ -68,8 +68,11 @@ public static void nextDoublesWithRange(double origin, double bound) {
SplittableRandom rg = new SplittableRandom(42L);
double value = rg.nextDouble(origin, bound);

assertTrue(value >= origin);
assertTrue(value < bound);
if (bound > 0) {
value = rg.nextDouble(bound); // Equivalent to nextDouble(0.0, bound)
assertTrue(value >= 0.0);
assertTrue(value < bound);
}
}

public static void assertTrue(boolean condition) {
Expand Down

1 comment on commit 3b40d21

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.