Created
March 15, 2012 20:18
-
-
Save roopeshvaddepally/2046636 to your computer and use it in GitHub Desktop.
Generate Random String of given length with alphabets
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
public static String generateString(int length) { | |
String characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
Random rng = new Random(); | |
char[] text = new char[length]; | |
for (int i = 0; i < length; i++) { | |
text[i] = characters.charAt(rng.nextInt(characters.length())); | |
} | |
return new String(text); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment