我正在生成一个随机密码。我的密码长度为 8 个字符,其中包含特殊字符。我需要保留first letter as alphabet
并且需要对剩余的七个字符进行洗牌,使其成为mixture of alphanumeric + ascii characters
.
public String generatePassword() {
int passwordLength = MAX_PASSWORD_LENGTH;
StringBuffer password = new StringBuffer(passwordLength);
//first character as an alphabet
password.append(RandomStringUtils.randomAlphabetic(1)).toString();
String alphaNumeric = RandomStringUtils.random(5, true, true);
String asciiChars = RandomStringUtils.randomAscii(2);
password.append(alphaNumeric).append(asciiChars);
return password.toString();
}
我需要一些帮助来随机播放最后 7 个字符。怎么做?