Java Utililty Methods ThreadLocalRandom

List of utility methods to do ThreadLocalRandom

Description

The list of methods to do ThreadLocalRandom are organized into topic(s).

Method

intrandomInteger(int min, int max)
Generates and returns a pseudorandom integer value between min and max (inclusive).
return ThreadLocalRandom.current().nextInt(min, max + 1);
ListrandomIntegerList(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();
intrandomNum(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;
ListrandomNums(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);
...
booleanrandomPer(long num, long divisor)
random Per
return ThreadLocalRandom.current().nextLong(0, divisor) < num;
floatrandomReal(float range)
random Real
ThreadLocalRandom rand = ThreadLocalRandom.current();
return (rand.nextFloat() - rand.nextFloat()) * range;
intrandomSeed()
random Seed
ThreadLocalRandom rnd = ThreadLocalRandom.current();
int seed;
do {
    seed = rnd.nextInt();
} while (seed == 0);
return seed;
StringrandomString()
random String
return UUID.randomUUID().toString();