1package com.runehive.util;
3import java.util.Arrays;
5import java.util.Random;
6import java.util.concurrent.ThreadLocalRandom;
31 private final ThreadLocalRandom
random = ThreadLocalRandom.current();
37 public ThreadLocalRandom
get() {
53 return random.nextInt((max - min) + 1) + min;
81 while(Arrays.binarySearch(exclude, result) >= 0) {
97 throw new IllegalArgumentException(
"range <= 0");
98 return random.nextFloat() * range;
107 return (
int) (
random.nextDouble() * array.length);
116 return array[(int) (
random.nextDouble() * array.length)];
125 return array[(int) (
random.nextDouble() * array.length)];
134 return array[(int) (
random.nextDouble() * array.length)];
143 return array[(int) (
random.nextDouble() * array.length)];
152 return array[(int) (
random.nextDouble() * array.length)];
161 return array[(int) (
random.nextDouble() * array.length)];
170 return array[(int) (
random.nextDouble() * array.length)];
179 return array[(int) (
random.nextDouble() * array.length)];
188 return array[(int) (
random.nextDouble() * array.length)];
197 return list.get((
int) (
random.nextDouble() * list.size()));
207 for(
int i = array.length - 1; i > 0; i--) {
208 int index =
random.nextInt(i + 1);
210 array[index] = array[i];
223 for(
int i = array.length - 1; i > 0; i--) {
224 int index =
random.nextInt(i + 1);
225 int a = array[index];
226 array[index] = array[i];
239 for(
int i = array.length - 1; i > 0; i--) {
240 int index =
random.nextInt(i + 1);
241 long a = array[index];
242 array[index] = array[i];
255 for(
int i = array.length - 1; i > 0; i--) {
256 int index =
random.nextInt(i + 1);
257 double a = array[index];
258 array[index] = array[i];
271 for(
int i = array.length - 1; i > 0; i--) {
272 int index =
random.nextInt(i + 1);
273 short a = array[index];
274 array[index] = array[i];
287 for(
int i = array.length - 1; i > 0; i--) {
288 int index =
random.nextInt(i + 1);
289 byte a = array[index];
290 array[index] = array[i];
303 for(
int i = array.length - 1; i > 0; i--) {
304 int index =
random.nextInt(i + 1);
305 float a = array[index];
306 array[index] = array[i];
319 for(
int i = array.length - 1; i > 0; i--) {
320 int index =
random.nextInt(i + 1);
321 boolean a = array[index];
322 array[index] = array[i];
334 for(
int i = array.length - 1; i > 0; i--) {
335 int index =
random.nextInt(i + 1);
336 char a = array[index];
337 array[index] = array[i];
350 return random.nextDouble() <= value;
The ThreadLocalRandom wrapper that provides additional functionality for generating pseudo-random num...
final ThreadLocalRandom random
The backing ThreadLocalRandom that will pseudorandomly generate numbers.
short random(short[] array)
Pseudo-randomly retrieves an short from this array.
char random(char[] array)
Pseudo-randomly retrieves an char from this array.
boolean[] shuffle(boolean[] array)
An implementation of the Fisher-Yates shuffle algorithm that will shuffle the elements of an boolean ...
short[] shuffle(short[] array)
An implementation of the Fisher-Yates shuffle algorithm that will shuffle the elements of an short ar...
public< T > T random(T[] array)
Pseudo-randomly retrieves a element from array.
float random(float[] array)
Pseudo-randomly retrieves an float from this array.
double random(double[] array)
Pseudo-randomly retrieves an double from this array.
int[] shuffle(int[] array)
An implementation of the Fisher-Yates shuffle algorithm that will shuffle the elements of an int arra...
int randomIndex(Object[] array)
Pseudo-randomly retrieves an index from array.
long[] shuffle(long[] array)
An implementation of the Fisher-Yates shuffle algorithm that will shuffle the elements of an long arr...
boolean random(boolean[] array)
Pseudo-randomly retrieves an boolean from this array.
char[] shuffle(char[] array)
An implementation of the Fisher-Yates shuffle algorithm that will shuffle the elements of an char arr...
long random(long[] array)
Pseudo-randomly retrieves an long from this array.
float[] shuffle(float[] array)
An implementation of the Fisher-Yates shuffle algorithm that will shuffle the elements of an float ar...
double[] shuffle(double[] array)
An implementation of the Fisher-Yates shuffle algorithm that will shuffle the elements of an double a...
int inclusiveExcludes(int min, int max, int... exclude)
Returns a pseudo-random int value between inclusive min and inclusive max excluding the specified num...
int inclusive(int min, int max)
Returns a pseudo-random int value between inclusive min and inclusive max.
byte[] shuffle(byte[] array)
An implementation of the Fisher-Yates shuffle algorithm that will shuffle the elements of an byte arr...
public< T > T random(List< T > list)
Pseudo-randomly retrieves a element from list.
int random(int[] array)
Pseudo-randomly retrieves an int from this array.
boolean success(double value)
Determines if a pseudorandomly generated double rounded to two decimal places is below or equal to va...
public< T > T[] shuffle(T[] array)
An implementation of the Fisher-Yates shuffle algorithm that will shuffle the elements of an T array.
float floatRandom(float range)
Returns a pseudo-random float between inclusive 0 and exclusive range.
byte random(byte[] array)
Pseudo-randomly retrieves an byte from this array.
int inclusive(int range)
Returns a pseudo-random int value between inclusive 0 and inclusive range.