Here you can find the source of getRandomString(int length)
public static String getRandomString(int length)
//package com.java2s; //License from project: Apache License import java.util.Random; public class Main { public static String getRandomString(int length) { char[] charaters = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; return getRandomString(length, charaters); }//from w ww .j ava 2 s .com public static String getRandomString(int length, char[] charaters) { StringBuilder sb = new StringBuilder(""); Random rn = new Random(); for (int i = 0; i < length; i++) { sb.append(charaters[rn.nextInt(charaters.length)]); } return sb.toString(); } }