longs
is an instance method of the Random
class used to generate an infinite stream of pseudorandom long
values, each adhering to the supplied origin (inclusive) and bound (exclusive).
The Random
class is defined in the java.util
package. To import the Random
class, use the following import statement.
import java.util.Random;
Public LongStream longs(long randomNumberOrigin, long randomNumberBound)
long randomNumberOrigin
: This is the origin of each value generated.long randomNumberBound
: This is the bound of each value generated.The method returns a stream of random long
values.
import java.util.Random;import java.util.stream.LongStream;public class Main{public static void main(String[] args) {Random random = new Random();long randomNumberOrigin = 1;long randomNumberBound = 7;LongStream ds = random.longs(randomNumberOrigin, randomNumberBound);ds.limit(10).forEach(System.out::println);}}
Random
class.LongStream
of random numbers. The lower and upper bounds are passed as parameters to the longs()
method.10
and print the generated random values.