阅读背景:

获取随机数,包含数字、大小写字母的密码

来源:互联网 
获取随机数
private  String getCharacterAndNumber(int length) {     String password = "";         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; //取得大写字母还是小写字母                 password += (char) (choice + random.nextInt(26));             }else if("num".equalsIgnoreCase(charOrNum)) {  // 数字              password += String.valueOf(random.nextInt(10));             }        }       return password;     }  private  String getCharacterAndNumber(i



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: