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--; } } }
原文:http://www.cnblogs.com/qj4d/p/6640472.html