# 随机生成6位数、随机生成不重复的6位数

int num = (int) ((Math.random() * 9 + 1) * 100000);

//随机的五位数
int num = (int) ((Math.random() * 9 + 1) * 10000);
//随机的七位数
int num = (int) ((Math.random() * 9 + 1) * 1000000);

//随机生成六位数，并且每位数都不重复
public static int Num() {
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];
}
if (String.valueOf(result).length() == 6) {
return result;
} else {
return Num();
}
}

····························································分割性·····························································

Math.random()的取值是0-1之间的随机小数（事实上取不到0和1）；

Math.random() * 9表示乘以9以后是0-9之间的随机小数，也就是0.****到8.****之间的小数（大于0而小于9）；

(Math.random() * 9 + 1)表示："+1"之后就会得到1－9之间的随机小数，也就是1.******到9.*******之间的小数；

((Math.random() * 9 + 1) * 100000)表示：乘以100000后，这个随机小数的小数点就会往后移六位,得到1*****.*****到9*****.******之间的数字（现在小数点前是六位数）；

        //生成一千个随机六位数
for (int i = 0; i < 5000; i++) {
int num = (int) ((Math.random() * 9 + 1) * 100000);
System.out.println("随机生成的六位数：" + num);
String num_str = String.valueOf(num);
//验证是否会生成五位数，或者首位是0的数
if (num_str.length() == 5) {
System.out.println("生成的五位数：" + num);
}
}