Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

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

Backport-of: 77b0240d44fd356711d75bc241e198f6f89ada8f
  • Loading branch information
jddarcy committed Feb 9, 2022
1 parent e1dfd9f commit 6202ea5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Expand Up @@ -677,7 +677,7 @@ public static double boundedNextDouble(RandomGenerator rng, double bound) {
double r = rng.nextDouble();
r = r * bound;
if (r >= bound) // may need to correct a rounding problem
r = Math.nextDown(r);
r = Math.nextDown(bound);
return r;
}

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 @@ -79,8 +79,11 @@ public long nextLong() {
};
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 6202ea5

@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.