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

intrandInt(int range)
generates a random integer value from 0 to (range-1)
return (int) (Math.random() * range);
intrandInt(int range)
rand Int
if (range < 1) {
    return 0;
return (int) (Math.random() * range);
intRandInt(int x, int y)
Rand Int
assert y >= x : "<RandInt>: y is less than x";
return rand.nextInt() % (y - x + 1) + x;
int[]randIntArray(int length)
rand Int Array
int array[] = new int[length];
List<Integer> list = new ArrayList<>();
for (int i = 0; i < length; i++) {
    list.add(i);
Random random = new Random();
for (int i = 0; i < length; i++) {
    array[i] = list.remove(random.nextInt(length - i));
...
int[]randIntArray(int length)
Generate a random array.
int[] ar = new int[length];
for (int i = 0; i < length; ++i) {
    ar[i] = generator.nextInt();
return ar;
doublerandIntv(double fr, double to)
rand Intv
return (to - fr) * RNG.nextDouble() + fr;
intrandLocation(int min, int max)
rand Location
double rand = Math.random();
int temp = (int) ((rand * (max - min)) + min);
if (((int) (rand * 1000) % 2) == 0) {
    temp *= -1;
return temp;
doubleRandom(int a, boolean Zero)
Random
if (Zero) {
    return Math.random() * a;
} else {
    return Math.random() * (a - 1) + 1;
Stringrandom(int length)
random
StringBuffer sb = new StringBuffer(length);
int radix = 126;
for (int i = 0; i < length; i++) {
    int c = new Double(Math.random() % radix * radix).intValue();
    if (c < 33)
        continue;
    sb.append((char) c);
return sb.toString();
Stringrandom(int length)
random
if (length > 16)
    length = 16;
String str = Math.random() + "";
return str.substring(str.length() - length);