Skip to content

Instantly share code, notes, and snippets.

@kakopappa
Created July 7, 2016 04:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kakopappa/6cb930b5053ccd3a58cdca80c4cd8258 to your computer and use it in GitHub Desktop.
Save kakopappa/6cb930b5053ccd3a58cdca80c4cd8258 to your computer and use it in GitHub Desktop.
public static final String allChar = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
public static final String letterChar = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
public static final String numberChar = "0123456789";
public static String generateString(int length)
{
StringBuffer sb = new StringBuffer();
SecureRandom random = new SecureRandom();
for (int i = 0; i < length; i++)
{
sb.append(allChar.charAt(random.nextInt(allChar.length())));
}
return sb.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment