1.Math.random()方法
// 生成六位数字验证码
String mobileCode = (int) ((Math.random() * 9 + 1) * 100000) + "";
System.out.println(mobileCode);
2.Random随机数
Random random = new Random();
String result = "";
for (int i = 0; i < 6; i++) {
//random.nextInt(10); 生成[0.9)的随机数一个,循环6次
result += random.nextInt(10);
}
System.out.println(result);
3 Random随机数 6位随机数 不足补0
String randomNumber = String.format("%06d", random.nextInt(999999));