50,855
社区成员
发帖
与我相关
我的任务
分享
Set<Integer> set = new HashSet<Integer>();
Random rand = new Random();
for(int i = 0; i < 10000; i++)
while(!set.add(rand.nextInt(900000) + 100000));
int[] array = {0,1,2,3,4,5,6,7,8,9};
Random rand = new Random();
for (int i = 10; i > 1; i--) {
int index = rand.nextInt(i);
int tmp = array[index];
array[index] = array[i - 1];
array[i - 1] = tmp;
}
int result = 0;
for(int i = 0; i < 6; i++)
result = result * 10 + array[i];
System.out.println(result);
Random random = new Random();
static Map tmp = new HashMap();
public static int generate() {
int i = random.nextInt(100000);
try {
return tmp.get(i) == null ? generate() : i;
} finally {
tmp.put(i, "");
}
}