当前位置:   article > 正文

生成大小写字母+数字的随机数_易语言valueof

易语言valueof
/**
* 生活数字、英文小写、大写的随机数
* @param length
* @return String 
* Date: Jun 17, 20142:50:13 PM
*/
private static String getCharAndNumr(int length, boolean hasNumAndChar) {
String val = "";
Random random = new Random();
for (int i = 0; i < length; i++) {
// 输出字母还是数字
String charOrNum = "";
if(hasNumAndChar){
charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num";
}else{
charOrNum = "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;
}
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/238811
推荐阅读
相关标签
  

闽ICP备14008679号