List of utility methods to do ThreadLocalRandom
String | RandomString(int length) Random String String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; StringBuffer buf = new StringBuffer(); for (int i = 0; i < length; i++) { int num = ThreadLocalRandom.current().nextInt(62); buf.append(str.charAt(num)); return buf.toString(); |
String | randomString(int minLength, int maxLength) random String Random random = ThreadLocalRandom.current();
return randomString(minLength, maxLength, random);
|
String | randomString(List random String return strings.get(ThreadLocalRandom.current().nextInt(strings.size()));
|
String[] | randomStringArray(int arrayLength, int stringLength) Generates a random array of String s with the given arguments. String[] array = new String[arrayLength]; for (int i = 0; i < array.length; i++) { array[i] = random(stringLength); return array; |
int | randomWorld() Returns a random integer that is a suitable value for both the id and randomNumber properties of a world object. return 1 + ThreadLocalRandom.current().nextInt(10000);
|
int | randomWorld() random World return 1 + ThreadLocalRandom.current().nextInt(10000);
|
T[] | shuffle(final T[] array) Shuffle the elements in the given array. if (array != null && array.length > 0) { for (int n = array.length; n > 1;) { final int randomIndex = ThreadLocalRandom.current().nextInt(n); n--; if (n != randomIndex) { final T tmp = array[randomIndex]; array[randomIndex] = array[n]; array[n] = tmp; ... |
void | shuffle(T[] arr) shuffle int n = arr.length; if (n <= 1) { return; for (int i = n - 1; i > 0; --i) { swap(arr, i, randomInt(i)); |
T[] | shuffle(T[] array) An implementation of the Fisher-Yates shuffle algorithm that will shuffle the elements of an T array. for (int i = array.length - 1; i > 0; i--) { int index = ThreadLocalRandom.current().nextInt(i + 1); T a = array[index]; array[index] = array[i]; array[i] = a; return array; |
int[] | shuffleArray(int[] ar) shuffle Array Random rnd = ThreadLocalRandom.current(); for (int i = ar.length - 1; i > 0; i--) { int index = rnd.nextInt(i + 1); int a = ar[index]; ar[index] = ar[i]; ar[i] = a; return ar; ... |