Java Utililty Methods Random

List of utility methods to do Random

Description

The list of methods to do Random are organized into topic(s).

Method

StringgenerateRandomNo()
It generates a random number and returns it as string.
int id = 0;
int range = Integer.MAX_VALUE / 3 * 2;
Random rand = new Random();
for (int i = 0; i < 1000; i++) {
    id = rand.nextInt(range);
return Integer.toString(id);
intGenerateRandomPin()
Generate Random Pin
int t = 0;
Random random = new Random();
for (int i = 0; i < MaxPinLength - 1; i++) {
    t += random.nextInt(9);
    t *= 10;
return t;
intgetItemID(Random r)
get Item ID
return nonUniformRandom(8191, 1, 100000, r);
intgetOreMultiplier(int fortune, Random r)
get Ore Multiplier
switch (fortune) {
case 1:
    return r.nextInt(3) == 0 ? 2 : 1;
case 2:
    switch (r.nextInt(4)) {
    case 0:
        return 2;
    case 1:
...
intgetPoisson(double lambda, Random rng)
Poisson-distributed RNG
double L = Math.exp(-lambda);
double p = 1.0;
int k = 0;
if (rng == null)
    rng = new Random();
do {
    k++;
    p *= rng.nextDouble();
...
RandomgetRandom()
get Random
if (random == null) {
    random = new Random();
    random.setSeed(System.currentTimeMillis());
return random;
RandomgetRandom()
get Random
return random;
RandomgetRandom()
get Random
if (random != null)
    return random;
else
    return getRandom(System.currentTimeMillis());
TgetRandom(Collection collection)
get Random
if (collection.isEmpty())
    return null;
int randomIndex = rnd.nextInt(collection.size());
int i = 0;
for (T obj : collection) {
    if (i == randomIndex)
        return obj;
    i = i + 1;
...
StringgetRandom(int i)
get Random
Random jjj = new Random();
if (i == 0)
    return "";
String jj = "";
for (int k = 0; k < i; k++) {
    jj = jj + jjj.nextInt(9);
return jj;
...