Here you can find the source of getRandomStringByLength(int length)
public static String getRandomStringByLength(int length)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { public static String getRandomStringByLength(int length) { if (length == 0) { length = 32;/* w ww.ja v a 2 s. c o m*/ } String base = "abcdefghijklmnopqrstuvwxyz0123456789"; Random random = new Random(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < length; i++) { int number = random.nextInt(base.length()); sb.append(base.charAt(number)); } return sb.toString(); } }