Skip to content

Instantly share code, notes, and snippets.

@shinshin86
Created August 27, 2016 05:25
Show Gist options
  • Save shinshin86/511ae1bf2c296b9f6cf5d3296d67d619 to your computer and use it in GitHub Desktop.
Save shinshin86/511ae1bf2c296b9f6cf5d3296d67d619 to your computer and use it in GitHub Desktop.
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