其他分享
首页 > 其他分享> > 手机验证码生成

手机验证码生成

作者:互联网

方式一

int code = UUID.randomUUID().hashCode() % 1000000;
char[] chars = new char[6];
for (int i = 0; i < chars.length; i++) {
    chars[i] = '0';
}
String verifyCode = new DecimalFormat(new String(chars)).format(Math.abs(code % 99999));
return verifyCode;

方式二

int number = UUID.randomUUID().hashCode() % 1000000;
int abs = Math.abs(number);
Random random = new Random();
StringBuffer buffer = new StringBuffer();
for (int i = 0 ; i < 6 ; i ++){
    int i1 = random.nextInt(10);
    buffer.append(i1);
}
String verifyCode = buffer.toString();
return verifyCode;

标签:String,int,chars,验证码,verifyCode,生成,abs,new,手机
来源: https://www.cnblogs.com/javacat7/p/14673780.html