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

UUIDrandom()
Create a new random UUID.
byte[] randomBytes = new byte[16];
if (IS_THREADLOCALRANDOM_AVAILABLE) {
    java.util.concurrent.ThreadLocalRandom.current().nextBytes(randomBytes);
} else {
    random.nextBytes(randomBytes);
long mostSigBits = 0;
for (int i = 0; i < 8; i++) {
...
Stringrandom(char lower, char upper, int length)
Generates a pseudorandom String object.
if (length < 0) {
    throw new IllegalArgumentException("length : " + length + " < 0 !");
StringBuilder sb = new StringBuilder(length);
for (int i = 0; i < length; i++) {
    sb.append(randomChar(lower, upper));
return sb.toString();
...
doublerandom(double min, double max)
Generate random double number in [min, max]
return ThreadLocalRandom.current().nextDouble(min, max + 0.00001);
intrandom(int min, int max)
random
Random rng = ThreadLocalRandom.current();
return rng.nextInt(max - min) + min;
Trandom(T[] array)
Pseudo-randomly retrieves a element from array .
return array[(int) (ThreadLocalRandom.current().nextDouble() * array.length)];
intrandomAge()
Random age.
return random.nextInt(MAX_AGE);
StringrandomAlphabetic(int length)
random Alphabetic
StringBuilder result = new StringBuilder();
for (int i = 0; i < length; i++) {
    char nextChar = (char) ('a' + random.nextInt('z' - 'a'));
    result.append(nextChar);
return result.toString();
intrandomBoundedInclusiveInt(int start, int end)
random Bounded Inclusive Int
return ThreadLocalRandom.current().nextInt(start, end + 1);
StringrandomCase(String input)
Flips the case of some characters in the input (about 50% of characters).
if (input != null) {
    StringBuilder output = new StringBuilder();
    for (int i = 0; i < input.length(); ++i) {
        char c = input.charAt(i);
        if (Character.isAlphabetic(c) && ThreadLocalRandom.current().nextDouble() < 0.5) {
            if (Character.isLowerCase(c))
                output.append(Character.toUpperCase(c));
            else if (Character.isUpperCase(c))
...
charrandomChar()
Generates a pseudorandom char value, from 0 to 65535 inclusive.
return randomChar(Character.MIN_VALUE, Character.MAX_VALUE);