What is the range of Random.nextDouble in Scala?

The Scaladoc page for Random ( http://www.scala-lang.org/api/current/scala/util/Random.html ) indicates that nextDouble "Returns the next pseudorandom case, a uniformly distributed double value between 0.0 and 1.0 from this sequence random number generators.

Quite vividly, it does not account for "inclusion." For example, are 0.0 and 1.0 possible? If so, which one (or both)? For example, if I am dividing by this number, I really want to make sure that 0 is not a return value. In other cases, I may not need 1.0. Obviously, this is difficult to obtain through testing, since there are about 10 ^ 15 values ​​between 0.0 and 1.0.

What is it? Please note, as not everyone can remember which of the "(" and "[" means "inclusive", just say "includes X".

+7
source share
1 answer

This is due to the fact that scala.util.Random is a very thin shell around java.util.Random ( see source ), which is documented in sufficient detail :

The general contract for nextDouble is that one double value, selected (approximately) evenly from the range 0.0d ( included ) to 1.0d ( exclusive ), is pseudo-randomly generated and returned.

+14
source

All Articles