(0.0,1.0)
(excluding 0.0 and 1.0).
The general contract of {@code nextDouble} is that one{@code double} value, chosen (approximately) uniformly from therange {@code 0.0d} (inclusive) to {@code 1.0d} (exclusive), ispseudorandomly generated and returned.
The method {@code nextDouble} is implemented by class {@code Random}as if by:
{@code}public double nextDouble() return (((long)next(26) << 27) + next(27)) / (double)(1L << 53); }}
The hedge "approximately" is used in the foregoing description only because the {@code next} method is only approximately an unbiasedsource of independently chosen bits. If it were a perfect source of randomly chosen bits, then the algorithm shown would choose {@code double} values from the stated range with perfect uniformity.
[In early versions of Java, the result was incorrectly calculated as:
{@code return (((long)next(27) << 27) + next(27)) / (double)(1L << 54);}This might seem to be equivalent, if not better, but in fact it introduced a large nonuniformity because of the bias in the rounding of floating-point numbers: it was three times as likely that the low-order bit of the significand would be 0 than that it would be 1! This nonuniformity probably doesn't matter much in practice, but we strive for perfection.] @return the next pseudorandom, uniformly distributed {@code double}value between {@code 0.0} and {@code 1.0} from thisrandom number generator's sequence @see Math#random
InputMismatchException
if the next token cannot be translated into a valid double value. If the translation is successful, the scanner advances past the input that matched. If the next token matches the Float regular expression defined above then the token is converted into a double value as if by removing all locale specific prefixes, group separators, and locale specific suffixes, then mapping non-ASCII digits into ASCII digits via {@link Character#digit Character.digit}, prepending a negative sign (-) if the locale specific negative prefixes and suffixes were present, and passing the resulting string to {@link Double#parseDouble Double.parseDouble}. If the token matches the localized NaN or infinity strings, then either "Nan" or "Infinity" is passed to {@link Double#parseDouble(String) Double.parseDouble} as appropriate. @return the double scanned from the input @throws InputMismatchException if the next token does not match the Float regular expression, or is out of range @throws NoSuchElementException if the input is exhausted @throws IllegalStateException if this scanner is closed
double
value between 0.0
and 1.0
from this random number generator's sequence.
@return the next pseudorandom, uniformly distributeddouble
value between 0.0
and 1.0
from this random number generator's sequence
double
value between 0.0
and 1.0
from this random number generator's sequence.
@return the next pseudorandom, uniformly distributeddouble
value between 0.0
and 1.0
from this random number generator's sequence
double
value between 0.0
and 1.0
from this random number generator's sequence.
@return the next pseudorandom, uniformly distributeddouble
value between 0.0
and 1.0
from this random number generator's sequence
double
value between 0.0
and 1.0
from this random number generator's sequence.
@return the next pseudorandom, uniformly distributeddouble
value between 0.0
and 1.0
from this random number generator's sequence
double
value between 0.0
and 1.0
from this random number generator's sequence.
@return the next pseudorandom, uniformly distributeddouble
value between 0.0
and 1.0
from this random number generator's sequence
double
value between 0.0
and 1.0
from this random number generator's sequence.
@return the next pseudorandom, uniformly distributeddouble
value between 0.0
and 1.0
from this random number generator's sequence
double
value between 0.0
and 1.0
from this random number generator's sequence.
@return the next pseudorandom, uniformly distributeddouble
value between 0.0
and 1.0
from this random number generator's sequence
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|