In Java 8, if you want to have a list
of non-repeating N
random integers in range (a, b)
, where b
is exclusive, you can use something like this:
Random random = new Random();
List<Integer> randomNumbers = random.ints(a, b).distinct().limit(N).boxed().collect(Collectors.toList());