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

intrandom(int min, int max)
random
return (int) (min + (max - min + 1) * Math.random());
intrandom(int min, int max)
random
double rand = Math.random();
double range = max - min;
double delta = range * rand;
return (int) Math.rint((min + delta));
intrandom(int n)
Get a random integer between 0 and n-1.
return (int) Math.floor(n * Math.random());
intrandom(int n)
random
if (n == 1) {
    return 0;
long r = ((nextLong() >>> 32) * n) >> 32;
return (int) r;
double[]random(int numSamples)
random
double[] x = null;
if (numSamples > 0) {
    x = new double[numSamples];
    for (int i = 0; i < numSamples; i++)
        x[i] = Math.random();
return x;
intrandom(int range)
sets a random amount in the range specified
if (range <= 0) {
    return 0;
return (int) (Math.random() * (range + 1));
intrandom(int start, int end)
random
return (int) Math.round(Math.random() * (end - start - 1)) + start;
intrandom(int theRange)
random
double myRandomNumber = Math.random() * (double) (theRange + 1);
return (int) myRandomNumber;
intrandom(int x)
Returns a random real number between 0 and x.
return (int) (Math.floor(Math.random() * x));
intrandom(int... array)
Returns a randomly selected element from the specified int array, as defined by Math#random() .
switch (array.length) {
case 0:
    return 0;
case 1:
    return array[0];
default:
    int selection = (int) (Math.random() * array.length);
    return array[selection];
...