List of utility methods to do ThreadLocalRandom
int | randomInteger(int min, int max) Generates and returns a pseudorandom integer value between min and max (inclusive). return ThreadLocalRandom.current().nextInt(min, max + 1);
|
List | randomIntegerList(int min, int max, int minLength, int maxLength) Returns a list of randomly generated integers using the minimum and maximum data point values and the minimum and maximum lengths. try { if (min >= max || minLength >= maxLength) { throw new IndexOutOfBoundsException("Index out of bounds generating random integer list."); List<Integer> list = new ArrayList<Integer>(); int length = ThreadLocalRandom.current().nextInt(minLength, maxLength + 1); for (int i = 0; i < length; i++) { list.add(ThreadLocalRandom.current().nextInt(min, max + 1)); ... |
long[] | randomLongs(final long count, final long min, final long max) random Longs final Random rand = ThreadLocalRandom.current(); final long[] randomNum = rand.longs(count, min, max + 1).toArray(); return randomNum; |
long[] | randomLongsNonDuplicates(final long count, final long min, final long max) random Longs Non Duplicates ThreadLocalRandom rng = ThreadLocalRandom.current(); Set<Long> generated = new LinkedHashSet<>(); while (generated.size() < count) { Long next = randLong(rng, min, max); generated.add(next); return generated.stream().mapToLong(i -> i).toArray(); |
int | randomNum(int min, int max) random Num if (min < 0) { int i = nextInt(max + 1 + Math.abs(min)); return min + i; } else { int i = nextInt(max + 1 - min); return min + i; |
List | randomNums(int min, int max, int count) random Nums if (max - min + 1 > count) { count = max - min + 1; Set<Integer> nums = new LinkedHashSet<Integer>(); while (nums.size() < count) { nums.add(randomNum(min, max)); List<Integer> list = new ArrayList<Integer>(nums); ... |
boolean | randomPer(long num, long divisor) random Per return ThreadLocalRandom.current().nextLong(0, divisor) < num;
|
float | randomReal(float range) random Real ThreadLocalRandom rand = ThreadLocalRandom.current();
return (rand.nextFloat() - rand.nextFloat()) * range;
|
int | randomSeed() random Seed ThreadLocalRandom rnd = ThreadLocalRandom.current(); int seed; do { seed = rnd.nextInt(); } while (seed == 0); return seed; |
String | randomString() random String return UUID.randomUUID().toString();
|