List of utility methods to do ThreadLocalRandom
void | randomDelay() random Delay int delayInMS = ThreadLocalRandom.current().nextInt(MIN_DELAY_IN_MS, MAX_DELAY_IN_MS); try { Thread.sleep(delayInMS); } catch (InterruptedException e) { throw new RuntimeException(e); |
double | randomDouble(final double min, final double max) Returns a random long at least min, <= max. if (max <= min) { throw new Exception("Invalid max <= min."); return ThreadLocalRandom.current().nextDouble(min, max); |
Collection | randomElement(Collection Selects pseudo-random elements from a collection List<E> out = new ArrayList<>(); List<E> l = new ArrayList<>(c); while (out.size() < n) { E e = l.get(ThreadLocalRandom.current().nextInt(0, l.size())); out.add(e); if (unique) l.remove(e); return out; |
T | randomEnum(Class random Enum return clazz.getEnumConstants()[ThreadLocalRandom.current().nextInt(clazz.getEnumConstants().length)];
|
long | randomFishType() random Fish Type return random.nextInt(4);
|
String | randomFixedChars(int size, List random Fixed Chars int[] indexs = randomIndexs(size, pool.size()); StringBuffer buf = new StringBuffer(); for (int i = 0; i < indexs.length; i++) { buf.append(pool.get(indexs[i])); return buf.toString(); |
int[] | randomIndexs(int count, int bound) random Indexs int[] indexs = new int[count]; for (int i = 0; i < count; i++) { indexs[i] = random.nextInt(bound); return indexs; |
int | randomInRange(int min, int max) random In Range int random = ThreadLocalRandom.current().nextInt(min, max + 1); return random; |
double | randomInt() random Int return ThreadLocalRandom.current().nextInt();
|
int | randomInt(int bound) Return randomize integer that is bounded by given bound return RANDOM.nextInt(bound);
|