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--; } } }
时间: 2024-10-27 13:32:03
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--; } } }