List of utility methods to do Random Int
int | randInt(int range) generates a random integer value from 0 to (range-1) return (int) (Math.random() * range); |
int | randInt(int range) rand Int if (range < 1) { return 0; return (int) (Math.random() * range); |
int | RandInt(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; |
double | randIntv(double fr, double to) rand Intv return (to - fr) * RNG.nextDouble() + fr;
|
int | randLocation(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; |
double | Random(int a, boolean Zero) Random if (Zero) { return Math.random() * a; } else { return Math.random() * (a - 1) + 1; |
String | random(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(); |
String | random(int length) random if (length > 16) length = 16; String str = Math.random() + ""; return str.substring(str.length() - length); |