Created
April 1, 2015 12:17
-
-
Save rafayali/17d6692ae48d0f616c86 to your computer and use it in GitHub Desktop.
Random string unique hash generator
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
private static char[] VALID_CHARACTERS = | |
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456879".toCharArray(); | |
public static String csRandomAlphaNumericString(int numChars) throws Exception{ | |
SecureRandom srand = new SecureRandom(); | |
Random rand = new Random(); | |
char[] buff = new char[numChars]; | |
for (int i = 0; i < numChars; ++i) { | |
if ((i % 10) == 0) { | |
rand.setSeed(srand.nextLong()); | |
} | |
buff[i] = VALID_CHARACTERS[rand.nextInt(VALID_CHARACTERS.length)]; | |
} | |
return new String(buff); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment