코드 사본은 다음과 같습니다.
패키지 com.phyl.password;
java.util.arraylist 가져 오기;
import java.util.arrays;
java.util.random import;
/**
* 문자 무작위로 생성 된 클래스
* @Author Asus
*
*/
공개 클래스 비밀번호 {
/**
* 비밀번호 유형 열거
* @Author Asus
*/
공개 정적 열거 유형 {
/**
* 문자 유형
*/
편지,
/**
*대문자 유형
*/
수도,
/**
* 디지털 유형
*/
숫자,
/**
* 기호 유형
*/
징후,
/**
* 큰 + 작은 문자 유형
*/
Letter_capital,
/**
* 작은 문자 + 숫자
*/
Letter_number,
/**
* 큰 + 작은 문자 + 번호 유형
*/
Letter_capital_number,
/**
* 큰 + 작은 문자 + 번호 + 기호
*/
Letter_capital_number_sign
}
개인 정적 문자열 [] 소문자 = {
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "k",
"l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x ","y ","z "};
개인 정적 문자열 [] capital = {
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "k",
"l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x ","y ","z "};
개인 정적 문자열 [] 번호 = {
"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"};
개인 정적 문자열 [] 부호 = {
"~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "+ ","` ","-"-", "=",
"{", "}", "|", ",": ","/"", "<", ">", "?",
"[", "]", "//", ";", ",", ",", ",", ",", ",", "/"};
/**
* 정적 임의 숫자
*/
개인 정적 임의 임의 = 새로운 랜덤 ();
public static void main (String [] args) {
System.out.println (password.getrandom (24, password.type.capital));
}
/**
* 임의의 조합 코드를 받으십시오
* @param num 숫자 수
* @param 유형
* @유형
* <br> 캐릭터 편지,
* <br> 자본,
* <br> 번호,
* <br> 기호 부호,
* <br> letter_capital,
* <br> 작은 문자 + 숫자 Letter_number,
* <br> 대형 + 작은 문자 + 숫자 lett_capital_number,
* <br> 대형 + 작은 문자 + 번호 + Symbolic Letter_capital_number_sign
*/
public static string getrandom (int num, 유형 유형) {
ArrayList <string> temp = new ArrayList <string> ();
StringBuffer Code = New StringBuffer ();
if (type == type.letter) {
temp.addall (arrays.aslist (소문자));
} else if (type == type.capital) {
temp.addall (Arrays.aslist (Capital));
} else if (type == type.number) {
temp.addall (arrays.aslist (number));
} else if (type == type.sign) {
temp.addall (arrays.aslist (sign));
} else if (type == type.letter_capital) {
temp.addall (arrays.aslist (소문자));
temp.addall (Arrays.aslist (Capital));
} else if (type == type.letter_number) {
temp.addall (arrays.aslist (소문자));
temp.addall (arrays.aslist (number));
} else if (type == type.letter_capital_number) {
temp.addall (arrays.aslist (소문자));
temp.addall (Arrays.aslist (Capital));
temp.addall (arrays.aslist (number));
} else if (type == type.letter_capital_number_sign) {
temp.addall (arrays.aslist (소문자));
temp.addall (Arrays.aslist (Capital));
temp.addall (arrays.aslist (number));
temp.addall (arrays.aslist (sign));
}
for (int i = 0; i <num; i ++) {
code.append (temp.get (random.nextint (temp.size ()));
}
return code.toString ();
}
}