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

StringrandomHexOfInt(int min, int max)
random Hex Of Int
int randomInt = randomIntWithMinMax(min, max);
return Integer.toHexString(randomInt);
floatrandomInIntervall(float low, float high)
random In Intervall
return (float) (Math.random() * (high - low) + low);
doublerandomInt(double arg)
random Int
double d = Math.ceil(Math.abs(arg));
return 1 + Math.floor(d * Math.random());
intrandomInt(final int max)
Returns a random int value between 0 and (max - 1).
return (int) (Math.random() * max);
intrandomInt(final int min, final int max)
Generate random integer over range specified by min and max, inclusively.
return min + (int) (Math.random() * (double) (max - min));
intrandomInt(final int upToNotInclusive)
random Int
final double rnd = Math.random() * upToNotInclusive;
int ret = (int) Math.floor(rnd);
if (ret == upToNotInclusive) {
    ret = 0;
return ret;
intrandomInt(int ceil)
Returns a random number between 0 and the int you pass
Random m = new Random(Calendar.getInstance().getTimeInMillis());
Random e = new Random(m.nextInt());
return (int) (e.nextFloat() * (ceil + 1));
intrandomInt(int fromInclusive, int toExclusive)
random Int
for (int i = 0; i < 1000; ++i) {
    int val = (int) Math.floor(Math.random() * (toExclusive - fromInclusive)) + fromInclusive;
    if (val >= fromInclusive && val < toExclusive) {
        return val;
throw new Error("Cannot generate random number in [" + fromInclusive + ", " + toExclusive + ")");
intrandomInt(int in)
{ method
if (in <= 1) {
    if (in == 1)
        return (0);
    throw new IllegalArgumentException("randomInt must take a number > 1");
int test = gRandomizer.nextInt(in);
if (test < 0)
    test = -test;
...
intrandomInt(int low, int high)
random Int
int range = high - low + 1;
return (int) (range * RANDOM.nextDouble()) + low;