Used to generate random numbers, sizes, and numbers for simple random Java generation. No special characters.
Copy Code code as follows:
package passwords;
Import Java.util.Random;
public class Pwdgen {
Private Random rdseed=new Random ();
/**
* @param
*length password length;
* @param
*letters Boolean non-capital letters combination control;
* @param
*LETTERS_CAPI Boolean capital letters combination control;
* @param
*numbers Boolean capital letters combination control;
*/
Public String getpwd (int length,boolean letters,boolean Letters_capi,boolean numbers) {
String res= "";
Random Rd=this.rdseed;
while (length-->0) {
Char _1dgt=0;
if (letters&&letters_capi&&numbers) {
int _key=rd.nextint (3);
if (2==_key) {
_1dgt=get_l ();
}else if (1==_key) {
_1dgt=get_l_c ();
}else if (0==_key) {
_1dgt=get_n ();
}
}else if (letters&&letters_capi&&!numbers) {
int _key=rd.nextint (2);
if (1==_key) {
_1dgt=get_l ();
}else if (0==_key) {
_1dgt=get_l_c ();
}
}else if (!letters&&letters_capi&&numbers) {
int _key=rd.nextint (2);
if (1==_key) {
_1dgt=get_n ();
}else if (0==_key) {
_1dgt=get_l_c ();
}
}else if (letters&&!letters_capi&&numbers) {
int _key=rd.nextint (2);
if (1==_key) {
_1dgt=get_l ();
}else if (0==_key) {
_1dgt=get_n ();
}
}else if (letters&&!letters_capi&&!numbers) {
_1dgt=get_l ();
}else if (!letters&&!letters_capi&&numbers) {
_1dgt=get_n ();
}else if (!letters&&letters_capi&&!numbers) {
_1dgt=get_l_c ();
}else{
Res=null;
Break
}
RES+=_1DGT;
}
return res;
}
Private char Get_l_c () {
Random Rd=this.rdseed;
int _dgt= (Rd.nextint (26) +65);
Return (char) _dgt;
}
Private char get_n () {
Random Rd=this.rdseed;
int _dgt= (Rd.nextint (10) +48);
Return (char) _dgt;
}
Private char get_l () {
Random Rd=this.rdseed;
int _dgt= (Rd.nextint (26) +97);
Return (char) _dgt;
}
Private char get_s () {
Random Rd=this.rdseed;
int _dgt= (Rd.nextint (14) +33);
Return (char) _dgt;
}
public static void Main (string[] args) {
Pwdgen test= new Pwdgen ();
int testct=1000000;
Long Start=system.nanotime ();
while (testct-->0) {
Test.getpwd (True, true, true);
}
Long end= system.nanotime ();
System.out.println ((double) (End-start))/(1000000000));
System.out.println (Test.getpwd (True, True, true));
}
}