Languages
[Edit]
EN

Java 8 - Int Stream API generate list with 10 random numbers

11 points
Created by:
JustMike
26150

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


Reference:

Random - Java Docs
IntStream - Java Docs

Native Advertising
50 000 ad impressions - 449$
🚀
Get your tech brand or product in front of software developers.
For more information contact us:
Red dot
Dirask - friendly IT community for everyone.

❤️💻 🙂

Join