Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate infinite DoubleStream

I can generate Stream<Double> using generate. E.g.

Stream.generate(Math::random).limit(10).forEach(System.out::println);

How to generate infinte random DoubleStream instead of Stream<Double>?

like image 419
peterbo Avatar asked Dec 15 '22 14:12

peterbo


1 Answers

You can use Random#doubles to generateDoubleStream

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().

E.g.

new Random().doubles().limit(10).forEach(System.out::println);
like image 74
sol4me Avatar answered Dec 27 '22 05:12

sol4me