package com.lsf.main;public class Test { public static void main(String[] args) { int authCode = makeAuthCode(); System.out.println(authCode); System.out.println("-----------------------------------"); } public static int makeAuthCode() { int authCodeNew = 0; authCodeNew = (int) Math.round(Math.random() * (9999 - 1000) + 1000); return authCodeNew; }}
——————————————————————————————————————————
最新更新:
下面是commons-lang3下的一个工具类,4表示几位的验证码,0-9表示验证码从这些数字生成public static String generateVerificationCode() { return RandomStringUtils.random(4, "0123456789");}
可以看看源代码如何实现的