Java Random doubles() method example

HQ » Java Tutorial » java.util » Random » doubles()
Java Random doubles() method example 2018-03-04T07:23:10+00:00

Description

The doubles() method of Random class returns an effectively unlimited stream of pseudorandom double values, each between zero (inclusive) and one (exclusive).
A pseudorandom double value is generated as if it’s the result of calling the method nextDouble().

Method Syntax

public DoubleStream doubles()

Method Argument

Data Type Parameter Description
N/A N/A N/A

Method Returns

The doubles() method of Random class returns a stream of pseudorandom double values.

Compatibility

Java 1.8

Discussion

The method double() is a convenience method of Random class. Basically it also returns the same value as nextDouble() method.

Implementation Note: This method is implemented to be equivalent to doubles(Long.MAX_VALUE).

Java Random doubles() Example

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

Basically on the above example, we put a limit on the number of values inside the Stream by calling the method limit and then by using the foreach method of DoubleStream class 10 random double values from range 0 to 1 has been printed out.

Sample Output

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

Java Random doubles() 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