Here you can find the source of getRandomString(int count)
public static String getRandomString(int count)
//package com.java2s; //License from project: Apache License import java.util.Random; public class Main { private static String[] chars = new String[] { "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" }; public static String getRandomString(int count) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < count; i++) sb.append(getRandomChar());/* w w w. ja va 2 s . c om*/ return sb.toString(); } public static String getRandomString(int count, boolean withInt) { StringBuilder sb = new StringBuilder(); if (withInt) for (int i = 0; i < count; i++) sb.append(getRandomChar()); else for (int i = 0; i < count; i++) sb.append(getRandomCharWithoutInt()); return sb.toString(); } private static String getRandomChar() { Random i = new Random(); return chars[i.nextInt(chars.length)]; } private static String getRandomCharWithoutInt() { Random i = new Random(); return chars[i.nextInt(26)]; } }