List of utility methods to do Random Int
int | random(int min, int max) random return (int) (min + (max - min + 1) * Math.random()); |
int | random(int min, int max) random double rand = Math.random(); double range = max - min; double delta = range * rand; return (int) Math.rint((min + delta)); |
int | random(int n) Get a random integer between 0 and n-1. return (int) Math.floor(n * Math.random()); |
int | random(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; |
int | random(int range) sets a random amount in the range specified if (range <= 0) { return 0; return (int) (Math.random() * (range + 1)); |
int | random(int start, int end) random return (int) Math.round(Math.random() * (end - start - 1)) + start; |
int | random(int theRange) random double myRandomNumber = Math.random() * (double) (theRange + 1); return (int) myRandomNumber; |
int | random(int x) Returns a random real number between 0 and x. return (int) (Math.floor(Math.random() * x)); |
int | random(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]; ... |