- Java.util Package Classes
- Java.util - Home
- Java.util - ArrayDeque
- Java.util - ArrayList
- Java.util - Arrays
- Java.util - BitSet
- Java.util - Calendar
- Java.util - Collections
- Java.util - Currency
- Java.util - Date
- Java.util - Dictionary
- Java.util - EnumMap
- Java.util - EnumSet
- Java.util - Formatter
- Java.util - GregorianCalendar
- Java.util - HashMap
- Java.util - HashSet
- Java.util - Hashtable
- Java.util - IdentityHashMap
- Java.util - LinkedHashMap
- Java.util - LinkedHashSet
- Java.util - LinkedList
- Java.util - ListResourceBundle
- Java.util - Locale
- Java.util - Observable
- Java.util - PriorityQueue
- Java.util - Properties
- Java.util - PropertyPermission
- Java.util - PropertyResourceBundle
- Java.util - Random
- Java.util - ResourceBundle
- Java.util - ResourceBundle.Control
- Java.util - Scanner
- Java.util - ServiceLoader
- Java.util - SimpleTimeZone
- Java.util - Stack
- Java.util - StringTokenizer
- Java.util - Timer
- Java.util - TimerTask
- Java.util - TimeZone
- Java.util - TreeMap
- Java.util - TreeSet
- Java.util - UUID
- Java.util - Vector
- Java.util - WeakHashMap
- Java.util Package Extras
- Java.util - Interfaces
- Java.util - Exceptions
- Java.util - Enumerations
- Java.util Useful Resources
- Java.util - Useful Resources
- Java.util - Discussion
java Random doubles() Method
Description
The java Random doubles() method 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().
Declaration
Following is the declaration for java.util.Random.doubles() method.
public DoubleStream doubles()
Parameters
NA
Return Value
The method call returns a stream of pseudorandom double values.
Exception
NA
java Random doubles(double randomNumberOrigin, double randomNumberBound) Method
Description
The java Random doubles(double randomNumberOrigin, double randomNumberBound) method returns an effectively unlimited stream of pseudorandom double values, each conforming to the given origin (inclusive) and bound (exclusive).
Declaration
Following is the declaration for java.util.Random.doubles(double randomNumberOrigin, double randomNumberBound) method.
public DoubleStream doubles(double randomNumberOrigin, double randomNumberBound)
Parameters
randomNumberOrigin − the origin (inclusive) of each random value
randomNumberBound − the bound (exclusive) of each random value
Return Value
The method call a stream of pseudorandom double values, each with the given origin (inclusive) and bound (exclusive).
Exception
IllegalArgumentException − if randomNumberOrigin is greater than or equal to randomNumberBound
java Random doubles(long streamSize) Method
Description
The java Random doubles(long streamSize) method returns a stream producing the given streamSize number 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().
Declaration
Following is the declaration for java.util.Random.doubles(long streamSize) method.
public DoubleStream doubles(long streamSize)
Parameters
long streamSize − the number of values to generate.
Return Value
The method call a stream of double values.
Exception
IllegalArgumentException − if streamSize is less than zero.
java Random doubles(long streamSize, double randomNumberOrigin, double randomNumberBound) Method
Description
The java Random doubles(long streamSize, double randomNumberOrigin, double randomNumberBound) method returns a stream producing the given streamSize number of pseudorandom double values, each conforming to the given origin (inclusive) and bound (exclusive).
Declaration
Following is the declaration for java.util.Random.doubles(long streamSize, double randomNumberOrigin, double randomNumberBound) method.
public DoubleStream doubles(long streamSize, double randomNumberOrigin, double randomNumberBound)
Parameters
long streamSize − the number of values to generate.
Return Value
The method call a stream of double values.
Exception
IllegalArgumentException − if streamSize is less than zero.
Getting a Random Double Number Example
The following example shows the usage of Java Random doubles() method. Firstly, we've created a Random object and then using doubles() we retrieved a stream of random double values and printed first value.
package com.tutorialspoint; import java.util.Random; import java.util.stream.DoubleStream; public class RandomDemo { public static void main( String args[] ) { // create random object DoubleStream randomNoStream = new Random().doubles(); // print a random double value randomNoStream.limit(1).forEach( i -> System.out.println(i)); } }
Output
Let us compile and run the above program, this will produce the following result.
0.5129590222446587
Getting a Random Double Number Between Given Two Numbers Example
The following example shows the usage of Java Random doubles(double randomNumberOrigin, double randomNumberBound) method. Firstly, we've created a Random object and then using doubles(double randomNumberOrigin, double randomNumberBound) we retrieved a stream of random double values and printed first value.
package com.tutorialspoint; import java.util.Random; import java.util.stream.DoubleStream; public class RandomDemo { public static void main( String args[] ) { // create random object DoubleStream randomNoStream = new Random().doubles(5,6); // print a random double value randomNoStream.limit(1).forEach( i -> System.out.println(i)); } }
Output
Let us compile and run the above program, this will produce the following result.
5.948299414215264
Getting a Stream of Random Double Numbers of Given Size Example
The following example shows the usage of Java Random doubles(long streamSize) method. Firstly, we've created a Random object and then using doubles(long streamSize) we retrieved a stream of a random double value and printed its value.
package com.tutorialspoint; import java.util.Random; import java.util.stream.DoubleStream; public class RandomDemo { public static void main( String args[] ) { // create random object DoubleStream randomNoStream = new Random().doubles(1); // print a random double value randomNoStream.forEach( i -> System.out.println(i)); } }
Output
Let us compile and run the above program, this will produce the following result.
0.716435513160095
Getting a Stream of Random Double Numbers of Given Size Between Given Two Numbers Example
The following example shows the usage of Java Random doubles(long streamSize, double randomNumberOrigin, double randomNumberBound) method. Firstly, we've created a Random object and then using doubles(long streamSize, double randomNumberOrigin, double randomNumberBound) we retrieved a stream of a random double value and printed its value.
package com.tutorialspoint; import java.util.Random; import java.util.stream.DoubleStream; public class RandomDemo { public static void main( String args[] ) { // create random object DoubleStream randomNoStream = new Random().doubles(1,5,6); // print a random double value randomNoStream.forEach( i -> System.out.println(i)); } }
Output
Let us compile and run the above program, this will produce the following result.
5.980651774805819
To Continue Learning Please Login
Login with Google