Languages
[Edit]
EN

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

11 points
Created by:
halfera
411

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

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join