List of utility methods to do ThreadLocalRandom
int | getRandom8() Generator an random int in 10^7 ~ 10^8 Use nextInt(int origin, int bound) in JDK 1.7 return ThreadLocalRandom.current().nextInt(10_000_000, 99_000_000);
|
int | getRandomBetween(int min, int max) get Random Between Preconditions.checkArgument(max > min);
return ThreadLocalRandom.current().nextInt(max - min) + min;
|
int | getRandomBoundedInt(int bound) bound is exclusive return ThreadLocalRandom.current().nextInt(bound);
|
double | getRandomDouble(double a, double b) get Random Double if (a == b) return a; return ThreadLocalRandom.current().nextDouble(a, b); |
E | getRandomElement(E[] array) get Random Element return array[getRandomInt(array.length)];
|
T | getRandomElement(List get Random Element int size = elements.size(); if (size > 0) { return elements.get(ThreadLocalRandom.current().nextInt(size)); } else { return null; |
float | getRandomFloat() returns (.nextFloat() * 10 ) * (1/2 chance of *= -1) float randomFloat = ThreadLocalRandom.current().nextFloat() * 10; float coinFlip = ThreadLocalRandom.current().nextInt(2); if (coinFlip > 0) { randomFloat *= -1; return randomFloat; |
String | getRandomId(@Nonnull Random random, int length) get Random Id final char[] buf = new char[length]; for (int i = 0; i < length; ++i) { buf[i] = RANDOM_ID_CHARS[random.nextInt(RANDOM_ID_CHARS.length)]; return new String(buf); |
int | getRandomInt() get Random Int return RANDOM.nextInt();
|
int | getRandomInt(int a, int b) get Random Int if (a == b) return a; if (a > b) return ThreadLocalRandom.current().nextInt(b, a); return ThreadLocalRandom.current().nextInt(a, b); |