Return to site

Java math random range

broken image
broken image

Then, we run collect() on the returned stream - not the original one.

broken image
broken image

However, you can specify a range, as well as the number of elements you'd like to generate.Īdditionally, the first argument is the number of elements you'd like to generate - otherwise, the stream will be generate an unlimited number of elements, until your Heap Memory space runs out: List intList = new Random().ints( 5, 1, 11)īefore collecting the IntStream, we'll have to box it via the boxed() method, which returns a stream consisting of the elements of the IntStream, boxed to an Integer. This is an unbounded IntStream, which will generate any value from Integer.MIN_VALUE to Integer.MAX_VALUE.

broken image