Here you can find the source of getRandomString()
public static String getRandomString()
//package com.java2s; // The MIT License import java.util.Random; public class Main { private static final Random RAND = new Random(); /**//from w w w .j a v a 2 s.co m * Returns a randomly generated string of up to 15 characters.<br><br> * * @return A randomly generated string */ public static String getRandomString() { return getRandomString(15); } /** * Returns a randomly generated string of up to X characters.<br><br> * * @param numChars the number of characters long the random string should be * * @return A randomly generated string */ public static String getRandomString(int numChars) { int chars = RAND.nextInt(numChars); while (chars == 0) chars = RAND.nextInt(numChars); StringBuffer sb = new StringBuffer(); for (int i = 0; i < chars; i++) { int index = 97 + RAND.nextInt(26); char c = (char) index; sb.append(c); } // for return sb.toString(); } }