/**
* 生成6位随机密码
* */
public class CreatePasswordUtil {
private static Random getR = new Random();
public static void main(String[] args) {
String print = getDigitalAndabcPwd();
System. out.println(print);
}
//6为数字的随机密码
public static long getDigitalPwd() {
long pass = Math.round(Math. random()*899999+100000);
return pass;
}
//6位随机密码,包括3位数字3位字母(字母区分大小写)
public static String getDigitalAndabcPwd() {
String s = "";
int n = 0;
int m = 0;
for (int i = 0; i < 6; i++) {
if (n == 3) {
s += CreatePasswordUtil. getSz();
m++;
} else if (m == 3) {
s += CreatePasswordUtil. getZm();
n++;
} else {
int ri = getR .nextInt(2);
int temp = ri == 0 ? m++ : n++;
s += ri == 0 ? CreatePasswordUtil. getSz() : CreatePasswordUtil.getZm();
}
}
return s;
}
// 随机数字的字母,区分大小写
private static String getZm() {
char sSS = (char) (getR.nextInt(26) + 97); // 小写字母97--122=a---z
char sBs = (char) (getR.nextInt(26) + 65); // 大写65--90=A----Z
char[] stemp = { sSS, sBs };
int i = getR .nextInt(2);
String sS = String. valueOf(stemp[i]);
return sS;
}
// 随机数字的字符串
private static String getSz() {
int getI = getR.nextInt(10) + 48;// 数字48--57=0---9
String sI = String. valueOf((char) getI);
return sI;
}
}