Java Random doubles(long streamSize, double randomNumberOrigin, double randomNumberBound) method example

HQ ┬╗ Java Tutorial ┬╗ java.util ┬╗ Random ┬╗ doubles(long streamSize, double randomNumberOrigin, double randomNumberBound)
Java Random doubles(long streamSize, double randomNumberOrigin, double randomNumberBound) method example 2018-03-04T07:22:24+00:00

java.util.Random doubles(long streamSize, double randomNumberOrigin, double randomNumberBound)

Description

The doubles(long streamSize, double randomNumberOrigin, double randomNumberBound) method of Random class is an overloaded method of doubles(). This is simply the same as calling DoubleStream doubles(double randomNumberOrigin, double randomNumberBound), the only thing added is the streamsize. In practice I believe that this method is unnecessary as DoubleStream method already has a limit() method which basically function the same.

Method Syntax

public DoubleStream doubles(long streamSize, double randomNumberOrigin, double randomNumberBound)

Method Argument

Data Type Parameter Description
long streamSize the number of values to generate
double randomNumberOrigin the origin (inclusive) of each random value
double randomNumberBound the bound (exclusive) of each random value

Method Returns

The doubles(long streamSize, double randomNumberOrigin, double randomNumberBound) method of Random class returns a stream of pseudorandom double values, each with the given origin (inclusive) and bound (exclusive)

Compatibility

Java 1.8

Discussion

The method doubles(long streamSize, double randomNumberOrigin, double randomNumberBound) is an overloaded method of doubles() wherein on this method requires three input which is randomNumberOrigin, randomNumberBound and streamSize.

By calling this method a┬ápseudorandom double value is generated as if it’s the result of calling the following method with the origin and bound:

Notes:

The following exception can be thrown

IllegalArgumentException – if streamSize is less than zero
IllegalArgumentException – if randomNumberOrigin is greater than or equal to randomNumberBound

Java Random doubles(long streamSize, double randomNumberOrigin, double randomNumberBound) Example

Below is a simple java example on the usage of doubles() method of Random class.

On the above example, we have used a value streamSize=5, randomNumberOrigin=1, and randomNumberBound=10. So the result would be a 5 random numbers with range 1 to 10.

Sample Output

Below is the sample output when you run the above example.

Java Random doubles(streamsize, origin, bound) example output

Suggested Reading List

Contact Info

Singapore

Our Goal

JavaTutorialHQ aims to to be The Ultimate Guide on Java with hundreds of examples from basic to advance Topics.

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close