Created
August 27, 2016 05:25
-
-
Save shinshin86/511ae1bf2c296b9f6cf5d3296d67d619 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Random; | |
public class PasswordGenerate { | |
/** | |
* Password generate | |
* | |
* @param passLength | |
* Password length | |
* @return | |
* password | |
*/ | |
public static String generate(int passLength){ | |
int length = passLength; | |
StringBuilder material = new StringBuilder(); | |
StringBuilder result = new StringBuilder(); | |
for(int i = 0x30;i < 0x3a; i++){ | |
material.append((char)i); | |
} | |
for(int i = 0x41; i < 0x5a; i++){ | |
material.append((char)i); | |
} | |
for(int i = 0x61; i < 0x7a; i++){ | |
material.append((char)i); | |
} | |
Random random = new Random(); | |
while(result.length() < length){ | |
result.append(material.charAt(random.nextInt(material.length()))); | |
} | |
return result.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment