Skip to content

Instantly share code, notes, and snippets.

@roopeshvaddepally
Created March 15, 2012 20:18
Show Gist options
  • Save roopeshvaddepally/2046636 to your computer and use it in GitHub Desktop.
Save roopeshvaddepally/2046636 to your computer and use it in GitHub Desktop.
Generate Random String of given length with alphabets
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