Unique Random Numbers

Thanking Java's stream feature, it is easy to generate a list of unique random numbers. For example, we want to pick up 6 lucky numbers for Lotto which ranges from 1 to 59.

new Random().ints(1, 59+1).distinct().limit(6).sorted().boxed().collect(Collectors.toList());


Comments

Popular posts from this blog

[Event] JManc (28th June 2024)

Tales from Earthsea

Real View Will