Here you can find the source of getRandomString(int length)
public static String getRandomString(int length)
//package com.java2s; //License from project: Apache License import java.util.List; import java.util.Random; public class Main { public static String getRandomString(int length) { if (length <= 0) { return ""; }/*from w w w .j ava 2 s . co m*/ char[] randomChar = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm' }; Random random = new Random(); StringBuffer stringBuffer = new StringBuffer(); for (int i = 0; i < length; i++) { stringBuffer.append(randomChar[Math.abs(random.nextInt()) % randomChar.length]); } return stringBuffer.toString(); } public static String toString(List<String> list, String separator) { StringBuffer stringBuffer = new StringBuffer(); for (String str : list) { stringBuffer.append(separator + str); } stringBuffer.deleteCharAt(0); return stringBuffer.toString(); } }