Java Utililty Methods Random Long

List of utility methods to do Random Long

Description

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

Method

LongrandLong(long minimum, long maximum)
rand Long
assert minimum <= maximum;
long value = Math.abs(seed.nextLong()) % (maximum - minimum + 1) + minimum;
assert minimum <= value && value <= maximum;
return value;
longrandLong(long n)
rand Long
long bits, val;
do {
    bits = (new Random().nextLong() << 1) >>> 1;
    val = bits % n;
} while (bits - val + (n - 1) < 0L);
return val;
longrandom(long begin, long end)
random
long rd = begin + (long) (Math.random() * (end - begin));
if (rd == begin || rd == end) {
    return random(begin, end);
return rd;
longrandom(long max)
random
return (long) (Math.random() * max);
longrandom(long min, long max)
Returns a random long number between the value min and the value max.
if (min > max) {
    throw new ArithmeticException(
            "min" + String.valueOf(min) + "Value min " + min + " must be lesser than value max " + max);
return (long) (Math.random() * (max - min) + min);
longrandom(long range)
Returns a random value in the range [1 - range]
return (long) ((Math.random() * 100000) % range) + 1;
StringrandomHexOfLong(long max)
random Hex Of Long
long randomInt = randomLongWithMinMax(0, max);
return Long.toHexString(randomInt);
longrandomLong()
random Long
x ^= (x << 21);
x ^= (x >>> 35);
x ^= (x << 4);
return Math.abs(x);
longrandomLong()
random Long
return RND.nextLong();
longrandomLong(long min, long max)
Generates pseudo-random long from specific range.
return min + (long) (Math.random() * (max - min));