/**
* 获得随意长度数字加字母验证码字符串
* @param length 随意长度
* @return 字符串
*/
public static String getCharacterAndNumber(int length){
String val = "";
Random random = new Random();
for (int i = 0; i < length; i++) {
String charOrNum = random.nextInt(2)%2==0?"char":"num";
if ("char".equalsIgnoreCase(charOrNum))
{
int choice =random.nextInt(2)%2==0?65:97;
val +=(char)(choice+random.nextInt(26));
} else if("num".equalsIgnoreCase(charOrNum)){
val += String.valueOf(random.nextInt(10));
}
}
return val;
}
生成字母加数字字符串方法
最新推荐文章于 2021-12-06 14:56:06 发布