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 { private static final char[] SOURCE = "123456789abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ" .toCharArray();//ww w . ja v a 2 s .c om public static String getRandomStr(int length) { if (length < 1) { return null; } Random random = new Random(); char[] buf = new char[length]; int index = 0; for (int i = 0; i < length; i++) { index = random.nextInt(SOURCE.length); buf[i] = SOURCE[index]; } return new String(buf); } }