public class RandomUtil { private static final String ALPHA_NUMBER = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"; private static final String NUMBER = "0123456789"; private static final Random RANDOM; static { long timeInMillis = SystemClock.getTimeInMillis(); RANDOM = new Random(timeInMillis); } public static String randomNum(int len) { return random(NUMBER, len); } public static String randomStr(int len) { return random(ALPHA_NUMBER, len); } private static String random(String base, int len) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < len; i++) { int number = RANDOM.nextInt(base.length()); sb.append(base.charAt(number)); } return sb.toString(); }}