Here you can find the source of getRandomStr(int length)
public static String getRandomStr(int length)
//package com.java2s; //License from project: Apache License import java.util.Random; public class Main { public static String getRandomStr(int length) { Random randGen = null;//from w w w.j av a2s . co m char[] numbersAndLetters = null; Object initLock = new Object(); 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); } }