Here you can find the source of randomString(int length)
public static String randomString(int length)
//package com.java2s; /*/*from w w w . j av a 2 s . co m*/ * @(#)Util.java 1.00 2005/03/16 * @author Denny * Copyright (c) 1994-2005 Teansun, Inc. * All rights reserved. * * This software is the confidential and proprietary information of Teamsun, Inc. * You shall not disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered into with Teamsun. * */ import java.util.*; public class Main { private static Random randGen = null; private static char[] numbersAndLetters = null; private static Object initLock = new Object(); public static String randomString(int length) { if (length < 1) { return null; } if (randGen == null) { synchronized (initLock) { if (randGen == null) { randGen = new Random(); numbersAndLetters = ("0123456789abcdefghijklmnopqrstuvwxyz" + "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ").toCharArray(); } } } char[] randBuffer = new char[length]; for (int i = 0; i < randBuffer.length; i++) { randBuffer[i] = numbersAndLetters[randGen.nextInt(71)]; } return new String(randBuffer); } }