The Scaladoc page for Random ( http://www.scala-lang.org/api/current/scala/util/Random.html ) specifies that nextDouble "Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 from this random number generator's sequence."
Pretty glaringly, it leaves out "inclusion". For instance, are value 0.0 and 1.0 possible? If so, which one (or both)? For instance, if I am dividing by this number, I'd really want to make sure that 0 was not a returned value. In other cases, I might not want 1.0. Quite obviously, this is hard to get via testing, as there about 10^15 values between 0.0 and 1.0.
Which is it? Please note, since not everyone can remember which of "(" and "[" means "inclusive", please just say "includes X".
Gets the next random Double value uniformly distributed between 0 (inclusive) and 1 (exclusive).
In order to generate Random double type numbers in Java, we use the nextDouble() method of the java. util. Random class. This returns the next random double value between 0.0 (inclusive) and 1.0 (exclusive) from the random generator sequence.
This is due to the fact that scala.util.Random
is a very thin wrapper around java.util.Random
(see the source), which is documented in sufficient detail:
The general contract of nextDouble is that one double value, chosen (approximately) uniformly from the range 0.0d (inclusive) to 1.0d (exclusive), is pseudorandomly generated and returned.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With