Here you can find the source of genRandomNum(int pwd_len)
public static String genRandomNum(int pwd_len)
//package com.java2s; import java.util.Random; public class Main { public static String genRandomNum(int pwd_len) { final int maxNum = 36; int i;/* w ww . jav a2 s .c om*/ int count = 0; char[] str = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; 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(); } }