List of utility methods to do ThreadLocalRandom
String | generateString(Random rng, String characters, int length) generate String char[] text = new char[length]; for (int i = 0; i < length; i++) { text[i] = characters.charAt(rng.nextInt(characters.length())); return new String(text); |
String | generateStringFromCharacters(final Random random, final char[] validChars, final int min, final int max) Generate a random string from an array of characters final int size = ThreadLocalRandom.current().nextInt(min, max + 1); final char[] localPart = new char[size]; for (int i = 0; i < size; i++) { localPart[i] = validChars[random.nextInt(validChars.length - 1)]; return new String(localPart); |
String | genRandomString() gen Random String int len = getRandomInt(23) + 1; List<Integer> asciiBase = Arrays.asList(65, 97); StringBuilder sb = new StringBuilder(); for (int i = 0; i < len; i++) { int randChar = getRandomInt(26); sb.append(Character.toChars(randChar + asciiBase.get(getRandomInt(asciiBase.size())))); return sb.toString(); ... |
int | get_a_number_between_min_and_max(int min, int max) genumbebetweemianmax return java.util.concurrent.ThreadLocalRandom.current().nextInt(min, max + 1);
|
boolean | getBoolean() get Boolean return ThreadLocalRandom.current().nextBoolean();
|
boolean | getElement(boolean[] array) get Element return array[getInt(array.length)];
|
int | getInt(int bound) get Int return ThreadLocalRandom.current().nextInt(bound);
|
String | getLetter() get Letter String[] let = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x" + "y" + "z" }; letter = let[ThreadLocalRandom.current().nextInt(let.length)]; return letter; |
ThreadLocalRandom | getRandom() get Random return ThreadLocalRandom.current();
|
int | getRandom(int p) Generator an random int by 10^(p-1) Use nextInt(int origin, int bound) in JDK 1.7 if (p <= 0 && p > 9) return -1; return ThreadLocalRandom.current().nextInt((int) Math.pow(10, p - 1), (int) Math.pow(10, p) - 1); |