Here you can find the source of generateRandom(int length, int type)
public static String generateRandom(int length, int type)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { public static String generateRandom(int length, int type) { if (1 == type) { Random r = new Random(); int randNum = 0; while (randNum < 100000) { randNum = (int) r.nextInt(999999); }//from w w w.j a v a 2 s. c o m return randNum + ""; } String base = null; if (2 == type) { base = "abcdefghijklmnopqrstuvwxyz"; } else { 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(); } }