List of utility methods to do ThreadLocalRandom
UUID | random() 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++) { ... |
String | random(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(); ... |
double | random(double min, double max) Generate random double number in [min, max] return ThreadLocalRandom.current().nextDouble(min, max + 0.00001);
|
int | random(int min, int max) random Random rng = ThreadLocalRandom.current();
return rng.nextInt(max - min) + min;
|
T | random(T[] array) Pseudo-randomly retrieves a element from array . return array[(int) (ThreadLocalRandom.current().nextDouble() * array.length)]; |
int | randomAge() Random age. return random.nextInt(MAX_AGE);
|
String | randomAlphabetic(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(); |
int | randomBoundedInclusiveInt(int start, int end) random Bounded Inclusive Int return ThreadLocalRandom.current().nextInt(start, end + 1);
|
String | randomCase(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)) ... |
char | randomChar() Generates a pseudorandom char value, from 0 to 65535 inclusive. return randomChar(Character.MIN_VALUE, Character.MAX_VALUE);
|