List of utility methods to do Random
double | randomInRange(double min, double max) random In Range double range = max - min; double scaled = random.nextDouble() * range; return scaled + min; |
Iterator | randomInsults() random Insults return randomInsults(42);
|
int[] | randomIntArray(int len, Random rand) random Int Array int[] out = new int[len]; for (int i = 0; i < len; i++) { out[i] = rand.nextInt(); if (out[i] < 0) out[i] = -out[i]; return out; |
List | randomIntegerList(int sz, int min, int max) random Integer List List<Integer> lst = new ArrayList<>(sz); for (int i = 0; i < sz; i++) lst.add(randInt(min, max)); return lst; |
List | randomIntegers(int sz) random Integers List<Integer> lst = new ArrayList<>(); Random rand = new Random(); for (int i = 0; i < sz; i++) { lst.add(rand.nextInt(sz * 10)); return lst; |
Iterable | randomIterable(Collection Takes given collection, shuffles it and returns iterable instance. List<T> list = new ArrayList<>(col); Collections.shuffle(list); return list; |
String | randomKey() random Key byte[] key = new byte[16]; for (int i = 0; i < 16; i++) { key[i] = (byte) (-128 + (int) (Math.random() * ((127 - -128) + 1))); return new String(key); |
String | randomKey() Method to generate random key return Long.toHexString(Double.doubleToLongBits(Math.random()));
|
char | randomLetter() random Letter return letters[rand.nextInt(letters.length)];
|
List | randomList(Collection random List List<E> list = new ArrayList<>(collection); Collections.shuffle(list); return list; |