Java Random Number getNumber()

Here you can find the source of getNumber()

Description

get Number

License

Apache License

Declaration

public static String getNumber() 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.Random;

public class Main {
    private static final Random RANDOM = new Random();
    private static final char[] NUMBER = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
    private static final int NUMBER_LENGTH = NUMBER.length;

    public static String getNumber() {
        return getNumber(2);
    }//from  ww  w .  j  a va  2 s  . com

    public static String getNumber(int n) {
        StringBuilder res = new StringBuilder();
        for (int i = 0; i < n; i++)
            res.append(NUMBER[RANDOM.nextInt(NUMBER_LENGTH)]);
        return res.toString();
    }
}

Related

  1. getDocumentNumber()
  2. getFlightNumber()
  3. getNextRandomNumber()
  4. getNum(int length)
  5. getNumAndWord(int length)
  6. getNumber()
  7. getNumber(int _nX0, int _nX1)
  8. getNumber(int length)
  9. getNumber(int length)