Java Random Number getRandomNumberString(int length)

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

Description

get Random Number String

License

Open Source License

Declaration

public static String getRandomNumberString(int length) 

Method Source Code

//package com.java2s;

import java.util.Random;

public class Main {
    public static final String NUMBERS = "0123456789";

    public static String getRandomNumberString(int length) {
        Random rand = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int pos = rand.nextInt(NUMBERS.length());
            sb.append(NUMBERS.charAt(pos));
        }//from   www  .  j  a va  2s  .  com
        return sb.toString();
    }

    public static String toString(Object obj) throws Exception {
        if (obj == null) {
            return "";
        } else {
            return obj.toString();
        }
    }
}

Related

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