We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent dbbf0bb commit dd8a057Copy full SHA for dd8a057
javalib/src/main/scala/java/util/concurrent/ThreadLocalRandom.scala
@@ -106,7 +106,13 @@ class ThreadLocalRandom extends Random {
106
if (least >= bound)
107
throw new IllegalArgumentException()
108
109
- nextDouble() * (bound - least) + least
+ /* Based on documentation for Random.doubles to avoid issue #2144 and other
110
+ * possible rounding up issues:
111
+ * https://docs.oracle.com/javase/8/docs/api/java/util/Random.html#doubles-double-double-
112
+ */
113
+ val next = nextDouble() * (bound - least) + least
114
+ if (next < bound) next
115
+ else Math.nextAfter(bound, Double.NegativeInfinity)
116
}
117
118
0 commit comments