手机验证码生成

方式一

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;
上一篇:Oracle术语


下一篇:[Postgres] Removing Data with SQL Delete, Truncate, and Drop