Java Random Number getRandomNumer(int length)

Here you can find the source of getRandomNumer(int length)

Description

get Random Numer

License

Open Source License

Declaration

public static String getRandomNumer(int length) 

Method Source Code


//package com.java2s;
import java.util.Random;

public class Main {

    public static String getRandomNumer(int length) {
        if (length > 9 || length < 1) {
            return null;
        }// w w w . ja  v a 2  s . c o  m
        int maxNum = (int) Math.pow(10, length);
        Random random = new Random(System.currentTimeMillis());
        int code = random.nextInt(maxNum - 1);
        return String.format("%0" + length + "d", code);
    }
}

Related

  1. getRandomNumberFixLength()
  2. getRandomNumberGenerator()
  3. getRandomNumberInRange(Random random, int min, int max)
  4. getRandomNumbers(int range, int count, Random rnd)
  5. getRandomNumberString(int length)
  6. getRandomNumericString(int maxlen)
  7. getRandomPortNumber()
  8. getRandonNumber(int range)
  9. getrannumber()