Here you can find the source of getRandomString(int strLength)
public static String getRandomString(int strLength)
//package com.java2s; //License from project: Apache License import java.util.Random; public class Main { public static String getRandomString(int strLength) { StringBuffer buffer = new StringBuffer(); Random random = new Random(); for (int i = 0; i < strLength; ++i) { int charInt; char c; if (random.nextBoolean()) { charInt = 48 + random.nextInt(10); c = (char) charInt; buffer.append(c);//from w w w. j a v a2 s . c om } else { if (random.nextBoolean()) { charInt = 65 + random.nextInt(26); } else { charInt = 97 + random.nextInt(26); } if (charInt == 79) { charInt = 111; } c = (char) charInt; buffer.append(c); } } return buffer.toString(); } }