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

Stringbase62Random()
base Random
return base62ToString(Math.abs(ThreadLocalRandom.current().nextLong()));
intcreateNewPin()
create New Pin
int randomNum = ThreadLocalRandom.current().nextInt(1, 10000);
return randomNum;
StringcreateRandom(int number)
create Random
long min = (long) Math.pow(10, number - 1) + 1;
long max = (long) Math.pow(10, number) - 1;
long result = (long) ThreadLocalRandom.current().nextDouble(min, max);
return result + "";
StringcreateRandomName()
create Random Name
return ("uniqueDb" + UUID.randomUUID() + ThreadLocalRandom.current().nextLong()).replaceAll("-", "")
        .toLowerCase();
StringcreateRandomNumbers(int length)
create Random Numbers
String numbers = "";
for (int i = 0; i < length; ++i) {
    int randomNumber = ThreadLocalRandom.current().nextInt(0, 9);
    numbers += Integer.toString(randomNumber);
return numbers;
StringgenerateDescription()
Generates a description for a random part using the arrays of constants #SIZE , #COLOUR , #SHAPE , #MATERIAL , and #NOUN .
ThreadLocalRandom r = ThreadLocalRandom.current();
StringBuilder sb = new StringBuilder(40);
sb.append(SIZE[r.nextInt(SIZE.length)]);
sb.append(' ');
sb.append(COLOUR[r.nextInt(COLOUR.length)]);
sb.append(' ');
sb.append(SHAPE[r.nextInt(SHAPE.length)]);
sb.append(' ');
...
double[]generateRandomDoubleVector(int dimension, double bottomLimit, double topLimit)
generate Random Double Vector
double[] position = new double[dimension];
for (int i = 0; i < dimension; i++) {
    position[i] = ThreadLocalRandom.current().nextDouble(bottomLimit, topLimit);
return position;
intgenerateRandomisedId()
Generate a randomized integer over [ Integer#MIN_VALUE , Integer#MAX_VALUE ] suitable for use as an Aeron Id.
return ThreadLocalRandom.current().nextInt();
byte[]generateRandomSalt(int saltSize)
generate Random Salt
byte[] randomSalt = new byte[saltSize];
ThreadLocalRandom.current().nextBytes(randomSalt);
return randomSalt;
StringgenerateString(int length)
generate String
StringBuffer sb = new StringBuffer();
for (int i = 0; i < length; i++) {
    int index = ThreadLocalRandom.current().nextInt(allChar.length());
    sb.append(allChar.charAt(index));
return sb.toString();