doubles
is an instance method of the Random
class used to generate a stream of random double
values. There are four different variants of the method:
doubles(long streamSize)
doubles()
doubles(long streamSize, double randomNumberOrigin, double randomNumberBound)
doubles(double randomNumberOrigin, double randomNumberBound)
The Random
class is defined in java.util
package. To import the Random
class, use the following import statement:
import java.util.Random;
doubles(long streamSize)
This method generates a stream of random double
values of the specified size:
public DoubleStream doubles(long streamSize)
long streamSize
: The size of the stream.The method returns a stream of random double
values.
import java.util.Random;public class Main{public static void main(String[] args) {//create an object of the Random classRandom random=new Random();// stream sizelong streamSize = 10;// using doubles generate stream of random doublesrandom.doubles(streamSize).forEach(System.out::println);}}
doubles()
This method generates an infinite stream of random double
values.
public DoubleStream doubles()
The method has no parameters.
The method returns a stream of random double
values.
import java.util.Random;public class Main{public static void main(String[] args) {//create an object of the Random classRandom random=new Random();// using doubles generate stream of random doublesrandom.doubles().limit(4).forEach(System.out::println);}}
doubles(long streamSize, double randomNumberOrigin, double randomNumberBound)
This method generates a stream of pseudorandom double
values of the provided size, each adhering to the supplied origin (inclusive) and bound (exclusive).
public DoubleStream doubles(long streamSize, double randomNumberOrigin, double randomNumberBound)
long streamSize
: The size of the stream.double randomNumberOrigin
: The origin of each value generated.double randomNumberBound
: The bound of each value generated.The method returns a stream of random double
values.
import java.util.Random;import java.util.stream.DoubleStream;public class Main{public static void main(String[] args) {//create an object of the Random classRandom random=new Random();// size of the streamint streamSize = 8;// origin of each random numberdouble randomNumberOrigin = 1.4;// bound of each random numberdouble randomNumberBound = 7.53;// Stream of random doubles generatedDoubleStream ds = random.doubles(streamSize, randomNumberOrigin, randomNumberBound);// print the generated random valuesds.forEach(System.out::println);}}
doubles(double randomNumberOrigin, double randomNumberBound)
This method generates an infinite stream of pseudorandom double
values, each adhering to the supplied origin (inclusive) and bound (exclusive).
public DoubleStream doubles(double randomNumberOrigin, double randomNumberBound)
double randomNumberOrigin
: The origin of each value generated.double randomNumberBound
: The bound of each value generated.The method returns a stream of random double
values.
import java.util.Random;import java.util.stream.DoubleStream;public class Main{public static void main(String[] args) {//create an object of the Random classRandom random=new Random();// origin of each random numberdouble randomNumberOrigin = 1.42;// bound of each random numberdouble randomNumberBound = 7.23;// Stream of random doubles generatedDoubleStream ds = random.doubles(randomNumberOrigin, randomNumberBound);// print the generated random valuesds.limit(10).forEach(System.out::println);}}