public static String getRandomString(int length) { final String s = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; SecureRandom sr = new SecureRandom(); StringBuilder sb = new StringBuilder(length); for (int i = 0; i < length; i++) { sb.append(s.charAt(sr.nextInt(s.length()))); } return sb.toString(); }