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

StringgetRandomValue(String prefix, long maxValue)
get Random Value
long randomLongValue = ThreadLocalRandom.current().nextLong(maxValue);
return prefix + randomLongValue;
StringgetTempPersistFileName(String baseFileName)
get Temp Persist File Name
return baseFileName + "." + ThreadLocalRandom.current().nextLong(Long.MAX_VALUE);
ThreadLocalRandomgetThreadLocalRandom()
get Thread Local Random
return ThreadLocalRandom.current();
booleanisRandomOccurrence(int pcLikelihood)
is Random Occurrence
if (pcLikelihood < 0 || pcLikelihood > 100) {
    throw new IllegalArgumentException();
int pc = ThreadLocalRandom.current().nextInt(100 + 1);
return (pc > 0 && pc <= pcLikelihood);
double[]moveInRadius(double[] position, double radius)
move In Radius
double[] newPosition = new double[position.length];
for (int i = 0; i < position.length; i++) {
    newPosition[i] = position[i] + ThreadLocalRandom.current().nextDouble(-radius, radius);
return newPosition;
longparseSeed(String seedString)
parse Seed
if (seedString == null || seedString.length() == 0)
    return ThreadLocalRandom.current().nextLong();
try {
    long j = Long.parseLong(seedString);
    if (j == 0L)
        throw new IllegalArgumentException("Zero (0) isn't a valid seed.");
    return j;
} catch (NumberFormatException numberformatexception) {
...
Erand(final Collection items)
rand
if (items.isEmpty()) {
    throw new IllegalArgumentException("Can't pick an item from zero items.");
final int rand = ThreadLocalRandom.current().nextInt(items.size());
int i = 0;
E result = null;
for (final E item : items) {
    if (i == rand) {
...
intrandInt(int min, int max)
Returns a pseudo-random number between min and max, inclusive.
Random rand = ThreadLocalRandom.current();
int randomNum = rand.nextInt((max - min) + 1) + min;
return randomNum;
Stringrandom()
random
String str = "";
for (int i = 0; i < 20; i++) {
    str += String.valueOf((ThreadLocalRandom.current().nextInt(0, 9)));
return str;
Randomrandom()
random
return ThreadLocalRandom.current();