Here you can find the source of getRandomNum(int pwd_len)
public static String getRandomNum(int pwd_len)
//package com.java2s; //License from project: Open Source License import java.util.Random; public class Main { public static String getRandomNum(int pwd_len) { String randomStr = "abcdefghijklmnopqrstuvwxyz0123456789"; final int maxNum = 36; int i;// w w w . j av a2s . co m int count = 0; char[] str = randomStr.toCharArray(); StringBuffer pwd = new StringBuffer(""); Random r = new Random(); while (count < pwd_len) { i = Math.abs(r.nextInt(maxNum)); if (i > 0 && i < str.length) { pwd.append(str[i]); count++; } } return pwd.toString(); } }