/**
* 生成随机的八位字母数字混合密码 */
public static String createNewPassword()
{
String newPassword = “”;
Random random = new Random();
// 参数length,表示生成几位随机数
for ( int i = 0; i < 8; i++ )
{
String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num";
// 输出字母还是数字
if ( "char".equalsIgnoreCase(charOrNum) )
{
// 输出是大写字母还是小写字母
int temp = random.nextInt(2) % 2 == 0 ? 65 : 97;
newPassword += (char) (random.nextInt(26) + temp);
} else if ( "num".equalsIgnoreCase(charOrNum) )
{
newPassword += String.valueOf(random.nextInt(10));
}
}
return newPassword;
}