public static void setRandom(int min, int max, int n, HashSet<Integer> set) { Random random = new Random(); for (int i = 0; i < n; i++) { int ranInt = random.nextInt(max - min + 1); if(!set.add(ranInt)){ i--; } } }