public class VerifyCode {
public static String getCode(int length){
String code = "";
for(int i=0;i<length;i++){
boolean boo = (int)(Math.random()*2)==0;
if(boo){
code += String.valueOf((int)(Math.random()*10));
}else {
int temp = (int)(Math.random()*2)==0?65:97;
char ch = (char)(Math.random()*26+temp);
code += String.valueOf(ch);
}
}
return code;
}
public static void main(String[] args) {
System.out.println(VerifyCode.getCode(6));
System.out.println("-----------------");
System.out.println(VerifyCode.getVerify(6));
}
public static String getVerify(int length){
String code = "";
String str = "0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASFGHJKLZXCVBNM";
String[] strs = str.split("");
for(int i = 0;i<length;i++){
code += strs[(int)(Math.random()*strs.length)];
}
return code;
}
}