Here you can find the source of genRandomNumberString(int numberCount)
public static String genRandomNumberString(int numberCount)
//package com.java2s; //License from project: Open Source License import java.util.Random; public class Main { private static final char[] DEFAULT_CHARS = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', }; private static final char[] NUMBER_CHARS = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', }; private static final char[] NONEZERO_NUMBER_CHARS = new char[] { '1', '2', '3', '4', '5', '6', '7', '8', '9', }; public static String genRandomNumberString(int numberCount) { return genRandomString(1, NONEZERO_NUMBER_CHARS) + genRandomString(numberCount - 1, NUMBER_CHARS); }// w w w . j a v a 2s .c o m public static String genRandomString(int count) { return genRandomString(count, DEFAULT_CHARS); } public static String genRandomString(int count, char[] elements) { StringBuffer sb = new StringBuffer(); int len = elements.length - 1; for (int i = 0; i < count; i++) { sb.append(elements[new Random(System.nanoTime()).nextInt(len)]); } return sb.toString(); } }