Here you can find the source of getRandomString()
public static String getRandomString()
//package com.java2s; //License from project: Open Source License import java.util.Random; public class Main { private static final String CHAR_LIST = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; public static String getRandomString() { StringBuffer randStr = new StringBuffer(); for (int i = 0; i < 3; i++) { int number = getRandomNumber(); char ch = CHAR_LIST.charAt(number); randStr.append(ch);/*from ww w .j ava2 s . co m*/ } return randStr.toString(); } public static int getRandomNumber() { int randomInt = 0; Random randomGenerator = new Random(); randomInt = randomGenerator.nextInt(CHAR_LIST.length()); if (randomInt - 1 == -1) { return randomInt; } else { return randomInt - 1; } } }