Java ThreadLocalRandom doubles() method
The doubles() method of Java ThreadLocalRandom class returns an effectively unlimited stream of pseudorandom double values. Each value must lie between 0 and 1. This method overrides doubles in class Random.
Syntax:
Parameter:
NA
Returns:
This method returns a stream of pseudorandom double values.
Example
Output:
stream of pseudorandom double value is: [email protected]
Java ThreadLocalRandom doubles(long streamSize) method
The doubles(long streamSize) method of Java ThreadLocalRandom class returns a stream producing the given streamSize number of pseudorandom double values. Each value must conform to the given 0 (inclusive) and 1 (exclusive). This method overrides doubles in class Random.
Syntax:
Parameter:
streamSize – It is the number of values to generate
Returns:
This method returns a stream of double values.
Exception:
IllegalArgumentException: This exception will throw if the streamSize is less than zero.
Example 1
Output:
stream of double value is: [email protected]
Example 2
Output:
Exception in thread "main" java.lang.IllegalArgumentException: size must be non-negative at java.base/java.util.concurrent.ThreadLocalRandom.doubles(Unknown Source) at tests.JavaNextIntExample1.main(ThreadLocalRandomDoublesExample2.java:8)
Java ThreadLocalRandom doubles(double randomNumberOrigin, double randomNumberBound) method
The doubles(double randomNumberOrigin, double randomNumberBound) method of Java ThreadLocalRandom class returns an effectively unlimited stream of pseudorandom double values. Each value must conform to the given origin (inclusive) and bound (exclusive). This method overrides doubles in class Random.
Syntax:
Parameter:
randomNumberOrigin: It is the origin (inclusive) of each random value.
randomNumberBound: It is the bound (exclusive) of each random value.
Returns:
This method returns a stream of pseudorandom double values.
Exception:
IllegalArgumentException: This exception will throw if randomNumberOrigin is greater than or equal to randomNumberBound.
Example 1
Output:
stream of pseudorandom double value is: [email protected]
Example 2
Output:
Exception in thread "main" java.lang.IllegalArgumentException: bound must be greater than origin at java.base/java.util.concurrent.ThreadLocalRandom.doubles(Unknown Source) at tests.JavaNextIntExample.main(ThreadLocalRandomDoublesExample2.java:7)
Java ThreadLocalRandom doubles(long streamSize, double randomNumberOrigin, double randomNumberBound) method
The doubles(long streamSize, double randomNumberOrigin, double randomNumberBound) method of Java ThreadLocalRandom class returns a stream producing the given streamSize number of pseudorandom double values. Each value must conform to the given origin (inclusive) and bound (exclusive). This method overrides doubles in class Random.
Syntax:
Parameter:
streamSize – It is the number of values to generate
randomNumberOrigin – It is the origin (inclusive) of each random value
randomNumberBound – It is the bound (exclusive) of each random value
Returns:
This method returns a stream of pseudorandom double values.
Exception:
- IllegalArgumentException: This exception will throw if the streamSize is less than zero.
- IllegalArgumentException: This exception will throw if the randomNumberOrigin is greater than or equal to randomNumberBound.
Example 1
Output:
stream of pseudorandom double value is: [email protected]
Example 2
Output:
Exception in thread "main" java.lang.IllegalArgumentException: size must be non-negative at java.base/java.util.concurrent.ThreadLocalRandom.doubles(Unknown Source) at tests.JavaNextIntExample1.main(ThreadLocalRandomDoublesExample2.java:7)