Creating an IntStream of Random Values
In Java SE 8, class SecureRandom
has overloaded methods ints, longs and doubles, which it inherits from class Random
(package java.util
). These methods return IntStream
, LongStream
and DoubleStream
, respectively, that represent streams of random numbers. Each method has four overloads. We describe the ints
overloads here—methods longs
and doubles
perform the same tasks for streams of long
and double
values, respectively:
• ints()
—creates an IntStream
for an infinite stream of random int
s. An infinite stream has an unknown number of elements—you use a short-circuiting terminal operation to complete processing on an infinite stream. We’ll use an infinite stream in Chapter 23 to find prime numbers with the ...
Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.