手机验证码生成

方式一

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;

手机验证码生成

上一篇:Android平台OpenGL ES/Assimp/OpenCV/GLM集成说明


下一篇:Android学习之SQLite数据库存储