Here you can find the source of getRndNumByLen(int lengthOfNumber)
Parameter | Description |
---|---|
lengthOfNumber | the length of the number string to be created. |
public static String getRndNumByLen(int lengthOfNumber)
//package com.java2s; //License from project: Apache License import java.util.Random; public class Main { /**// ww w . j av a 2 s . co m * generate specified length string with numbers. * * @param lengthOfNumber * the length of the number string to be created. */ public static String getRndNumByLen(int lengthOfNumber) { int i, count = 0; StringBuffer randomStr = new StringBuffer(""); Random rnd = new Random(); while (count < lengthOfNumber) { i = Math.abs(rnd.nextInt(9)); if (i == 0 && count == 0) { } else { randomStr.append(String.valueOf(i)); count++; } } return randomStr.toString(); } }