Java代码生成6位正整数随机数

一、规则:6位的正整数随机数
二、思路
1.因为数字不能以0开头,则通过random随机数,生成一个1-9的数字。
2.通过循环5次,拼接random生成的0-9的随机数,进最后生成一个符合要求的数字

/**
	 * @return java.lang.String
	 * @Author jaychou
	 * @Description TODO 生成六位正整数数字
	 * @Date 10:24 2021/7/16 0016
	 **/
	public static String verificationCode() {
		//生成六位随机正整数
		Random random = new Random();
		String verificationCode = String.valueOf(random.nextInt(9) + 1);
		for (int i = 0; i < 5; i++) {
			verificationCode += random.nextInt(10);
		}
		return verificationCode;
	}

4.多次测试输出结果
479365
558884
908735
678483


更多推荐