Here you can find the source of getRandomNumberString(int maxValue, int strLen)
public static String getRandomNumberString(int maxValue, int strLen)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { private static Random rnd = new Random(); public static String getRandomNumberString(int maxValue, int strLen) { return intPadString(rnd.nextInt(maxValue), strLen); }//from w w w .ja v a 2s .c o m public static String intPadString(int num, int strLen) { return leftPadString(String.valueOf(num), '0', strLen); } public static String leftPadString(String str, char pad, int length) { if (str.length() >= length) return str; StringBuffer sb = new StringBuffer(); while (sb.length() < length - str.length()) sb.append(pad); sb.append(str); return sb.toString(); } }