UUID随机验证码
代码:
public static void main(String[] args) {
//随机验证码
//5位数的随机数 UUID生成的是16进制的
String res = UUID.randomUUID().toString();
res=res.substring(0,5);
System.out.println(res);
System.out.println("-----------");
String str="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
str+=str.toLowerCase();
str+="0123456789";
//从所有的字符中随机称5个
/* int index = new Random().nextInt(str.length());
System.out.println(str.charAt(index));*/
StringBuilder stringBuilder = new StringBuilder(5);
//随机取5个
for (int i = 0; i < 5; i++) {
int index = new Random().nextInt(str.length());
char ch = str.charAt(index);
stringBuilder.append(ch);
}
System.out.println(stringBuilder);
}
joker_dj