EN
Java 8 - Int Stream API generate list with 10 random numbers
11
points
Java 8 - generate list with 10 random numbers
int size = 10;
int min = 55;
int max = 123;
List<Integer> randList = new Random().ints(size, min, max)
.boxed().collect(Collectors.toList());
// [69, 93, 83, 61, 63, 62, 107, 82, 110, 103]
System.out.println(randList);
Above example uses IntStream.ints
with 3 args
IntStream ints(long streamSize, int randomNumberOrigin, int randomNumberBound)
Param description:
@param streamSize the number of values to generate
@param randomNumberOrigin the origin (inclusive) of each random value
@param randomNumberBound the bound (exclusive) of each random value