Here you can find the source of getRandomString(int length)
public static String getRandomString(int length)
//package com.java2s; import java.util.Random; public class Main { public static String getRandomString(int length) { String base = "abcdefghijklmnopqrstuvwxyz0123456789"; return getRandomString(base, length); }// w ww . j a va 2 s .c om public static String getRandomString(String source, int length) { String rdm = null; if (notNOE(source)) { Random random = new Random(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < length; i++) { int number = random.nextInt(source.length()); sb.append(source.charAt(number)); } rdm = sb.toString(); } return rdm; } public static boolean notNOE(String param) { return !isNullOrEmpty(param); } public static boolean isNullOrEmpty(String param) { if (null == param || param.isEmpty()) return true; return false; } }