Here you can find the source of generateRandomString(int length)
public static String generateRandomString(int length)
//package com.java2s; //License from project: Apache License import java.util.Random; public class Main { private static final char[] RANDOM_CHARS = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ@._()" .toCharArray();// w w w. j av a2s . c om public static String generateRandomString(int length) { return generateRandomString(RANDOM_CHARS, length); } public static String generateRandomString(char[] randChars, int length) { if (length < 1) { return null; } Random rand = new Random(); int rLen = randChars.length; char[] newStr = new char[length]; for (int i = 0; i < length; i++) { newStr[i] = randChars[rand.nextInt(rLen)]; } return new String(newStr); } }