Java ThreadLocalRandom getRandom(int p)

Here you can find the source of getRandom(int p)

Description

Generator an random int by 10^(p-1) Use nextInt(int origin, int bound) in JDK 1.7

License

Open Source License

Parameter

Parameter Description
p p

Return

random int

Declaration

public static int getRandom(int p) 

Method Source Code


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

import java.util.concurrent.ThreadLocalRandom;

public class Main {
    /**// ww  w. j  a va  2 s  .  c o  m
     * Generator an random int by 10^(p-1)
     * Use nextInt(int origin, int bound) in JDK 1.7
     * @param p p
     * @return random int
     */
    public static int getRandom(int p) {
        if (p <= 0 && p > 9)
            return -1;
        return ThreadLocalRandom.current().nextInt((int) Math.pow(10, p - 1), (int) Math.pow(10, p) - 1);
    }
}

Related

  1. getBoolean()
  2. getElement(boolean[] array)
  3. getInt(int bound)
  4. getLetter()
  5. getRandom()
  6. getRandom8()
  7. getRandomBetween(int min, int max)
  8. getRandomBoundedInt(int bound)
  9. getRandomDouble(double a, double b)