Java Random Number getNumber(int length)

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

Description

get Number

License

Open Source License

Declaration

public static String getNumber(int length) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.Random;

public class Main {
    private static final char[] NUMBERS = "0123456789".toCharArray();
    private static Random r = new Random();

    public static String getNumber(int length) {
        StringBuilder sb = new StringBuilder(length);
        while (length-- > 0) {
            sb.append(randomChar(NUMBERS));
        }// w  w w  .  j a  v a 2  s . co m
        return sb.toString();
    }

    private static char randomChar(char[] letters) {
        int index = r.nextInt(letters.length);
        return letters[index];
    }
}

Related

  1. getNumber()
  2. getNumber()
  3. getNumber(int _nX0, int _nX1)
  4. getNumber(int length)
  5. getNumber(int length)
  6. getNumber(int seed)
  7. getNumberClose(int seed)
  8. getNumberedUsername(String fn, String ln)
  9. getNumberInRange(int minimum, int maximum)