Java Utililty Methods Random Int

List of utility methods to do Random Int

Description

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

Method

intgetRandomInt(int minimum, int maximum)
get Random Int
int diff = maximum - minimum;
if (diff == 0) {
    return maximum;
} else {
    return RANDOM.nextInt(diff) + minimum;
intgetRandomInt(int sek, int min, int max)
get Random Int
Random random = new Random();
int temp = 0;
do {
    temp = random.nextInt(sek);
} while (temp < min || temp > max);
return temp;
intgetRandomInt(int size)
get Random Int
return rand.nextInt(size + 1);
intgetRandomInt(Random rand, int lower, int upper)
get Random Int
int num = (int) Math.floor(rand.nextDouble() * (upper - lower + 1));
return num + lower;
intgetRandomInt(String level)
get Random Int
if (level.contains("-")) {
    String[] spl = level.split("-");
    return getRandomInt(Integer.parseInt(spl[0]), Integer.parseInt(spl[1]));
} else
    return Integer.parseInt(level);
IntegergetRandomIntBetween(int low, int high)
get Random Int Between
return new Random().nextInt(high - low) + low;
intgetRandomIntBetween(int mi, int ma)
get Random Int Between
int n = rm.nextInt();
while (n < mi || n > ma) {
    n = rm.nextInt();
return n;
intgetRandomInteger(int aStart, int aEnd)
get Random Integer
if (aStart > aEnd) {
    throw new IllegalArgumentException("Start cannot exceed End.");
Random aRandom = new Random();
long range = (long) aEnd - (long) aStart + 1;
long fraction = (long) (range * aRandom.nextDouble());
int randomNumber = (int) (fraction + aStart);
System.out.printf("Generated : " + randomNumber);
...
intgetRandomInteger(int min, int max)
Get a random value from an interval.
return min + RANDOM.nextInt(max + 1 - min);
Integer[]getRandomIntegerArray(Random rand, int size, int range)
get Random Integer Array
Integer[] array = new Integer[size];
for (int i = 0; i < size; i++)
    array[i] = rand.nextInt(range);
return array;