# 随机产生的唯一编号

2D阵列：

``````Random random = new Random();

int[][] arrayone = new int[4097][1];
boolean[][] used = new boolean[4097][1];

for(int b = 0; b < arrayone.length; b++) {
for(int i = 0; i < arrayone[b].length; i++) {
for (int number = 0; number < used.length; number++) {
for (int x = 0; number <used[number].length; x++) {

number = random.nextInt(99999)+1;

if (!used[number][x]){
used[number][x] = true;
arrayone[b][i] = number;
}
else {
while(used[number][x]) {
number = (int)(Math.random() * 99999 + 1);
if (!used[number][x]) {
used[number][x] = true;
arrayone[b][i]=number;
break;
}
}
}
}
}
}
}
``````

``````int[] arrayone = new int[4097];
boolean[] used = new boolean[4097];

for(int i = 0; i < arrayone.length; i++) {
int number = (int)(Math.random() * 99999 + 1);

if (!used[number]){
used[number] = true;
arrayone[i] = number;
}
else {
while(used[number]) {
number = (int)(Math.random() * 99999 + 1);
if (!used[number]) {
used[number] = true;
arrayone[i]=number;
break;
}
}
}
}
``````

``````boolean[] used = new boolean[4097];
``````

``````int number = (int)(Math.random() * 99999 + 1);
if (!used[number])
``````

0条评论