|
RuneHive-Game
|
The ThreadLocalRandom wrapper that provides additional functionality for generating pseudo-random numbers.
More...
Public Member Functions | |
| float | floatRandom (float range) |
Returns a pseudo-random float between inclusive 0 and exclusive range. | |
| ThreadLocalRandom | get () |
Gets the backing ThreadLocalRandom. | |
| int | inclusive (int min, int max) |
Returns a pseudo-random int value between inclusive min and inclusive max. | |
| int | inclusive (int range) |
Returns a pseudo-random int value between inclusive 0 and inclusive range. | |
| int | inclusiveExcludes (int min, int max, int... exclude) |
Returns a pseudo-random int value between inclusive min and inclusive max excluding the specified numbers within the excludes array. | |
| boolean | random (boolean[] array) |
Pseudo-randomly retrieves an boolean from this array. | |
| byte | random (byte[] array) |
Pseudo-randomly retrieves an byte from this array. | |
| char | random (char[] array) |
Pseudo-randomly retrieves an char from this array. | |
| double | random (double[] array) |
Pseudo-randomly retrieves an double from this array. | |
| float | random (float[] array) |
Pseudo-randomly retrieves an float from this array. | |
| int | random (int[] array) |
Pseudo-randomly retrieves an int from this array. | |
| long | random (long[] array) |
Pseudo-randomly retrieves an long from this array. | |
| short | random (short[] array) |
Pseudo-randomly retrieves an short from this array. | |
| int | randomIndex (Object[] array) |
Pseudo-randomly retrieves an index from array. | |
| boolean[] | shuffle (boolean[] array) |
An implementation of the Fisher-Yates shuffle algorithm that will shuffle the elements of an boolean array. | |
| byte[] | shuffle (byte[] array) |
An implementation of the Fisher-Yates shuffle algorithm that will shuffle the elements of an byte array. | |
| char[] | shuffle (char[] array) |
An implementation of the Fisher-Yates shuffle algorithm that will shuffle the elements of an char array. | |
| double[] | shuffle (double[] array) |
An implementation of the Fisher-Yates shuffle algorithm that will shuffle the elements of an double array. | |
| float[] | shuffle (float[] array) |
An implementation of the Fisher-Yates shuffle algorithm that will shuffle the elements of an float array. | |
| int[] | shuffle (int[] array) |
An implementation of the Fisher-Yates shuffle algorithm that will shuffle the elements of an int array. | |
| long[] | shuffle (long[] array) |
An implementation of the Fisher-Yates shuffle algorithm that will shuffle the elements of an long array. | |
| short[] | shuffle (short[] array) |
An implementation of the Fisher-Yates shuffle algorithm that will shuffle the elements of an short array. | |
| boolean | success (double value) |
Determines if a pseudorandomly generated double rounded to two decimal places is below or equal to value. | |
Package Functions | |
| public< T > T | random (List< T > list) |
Pseudo-randomly retrieves a element from list. | |
| public< T > T | random (T[] array) |
Pseudo-randomly retrieves a element from array. | |
| public< T > T[] | shuffle (T[] array) |
An implementation of the Fisher-Yates shuffle algorithm that will shuffle the elements of an T array. | |
Private Attributes | |
| final ThreadLocalRandom | random = ThreadLocalRandom.current() |
The backing ThreadLocalRandom that will pseudorandomly generate numbers. | |
The ThreadLocalRandom wrapper that provides additional functionality for generating pseudo-random numbers.
In order to avoid sharing instances of this class across multiple threads, this should only be instantiated locally unless certain that it will never be accessed by another thread.
Definition at line 16 of file RandomGen.java.
| float com.runehive.util.RandomGen.floatRandom | ( | float | range | ) |
Returns a pseudo-random float between inclusive 0 and exclusive range.
| range | The exclusive range. |
float. | IllegalArgumentException | If the specified range is less than 0. |
Definition at line 95 of file RandomGen.java.
References random.
| ThreadLocalRandom com.runehive.util.RandomGen.get | ( | ) |
Gets the backing ThreadLocalRandom.
Definition at line 37 of file RandomGen.java.
References random.
| int com.runehive.util.RandomGen.inclusive | ( | int | min, |
| int | max ) |
Returns a pseudo-random int value between inclusive min and inclusive max.
| min | the minimum inclusive number. |
| max | the maximum inclusive number. |
int. | IllegalArgumentException | if max - min + 1 is less than 0. |
Definition at line 49 of file RandomGen.java.
References random.
Referenced by inclusive(), inclusiveExcludes(), and com.runehive.game.world.entity.mob.npc.drop.NpcDrop.toItem().
| int com.runehive.util.RandomGen.inclusive | ( | int | range | ) |
Returns a pseudo-random int value between inclusive 0 and inclusive range.
| range | the maximum inclusive number. |
int. | IllegalArgumentException | if max - min + 1 is less than 0. |
Definition at line 63 of file RandomGen.java.
References inclusive().
| int com.runehive.util.RandomGen.inclusiveExcludes | ( | int | min, |
| int | max, | ||
| int... | exclude ) |
Returns a pseudo-random int value between inclusive min and inclusive max excluding the specified numbers within the excludes array.
| min | the minimum inclusive number. |
| max | the maximum inclusive number. |
int. | IllegalArgumentException | if max - min + 1 is less than 0. |
inclusive(int, int). Definition at line 77 of file RandomGen.java.
References inclusive().
| boolean com.runehive.util.RandomGen.random | ( | boolean[] | array | ) |
Pseudo-randomly retrieves an boolean from this array.
| array | the array to retrieve an boolean from. |
boolean retrieved from the array. Definition at line 178 of file RandomGen.java.
References random.
| byte com.runehive.util.RandomGen.random | ( | byte[] | array | ) |
Pseudo-randomly retrieves an byte from this array.
| array | the array to retrieve an byte from. |
byte retrieved from the array. Definition at line 160 of file RandomGen.java.
References random.
| char com.runehive.util.RandomGen.random | ( | char[] | array | ) |
Pseudo-randomly retrieves an char from this array.
| array | the array to retrieve an char from. |
char retrieved from the array. Definition at line 187 of file RandomGen.java.
References random.
| double com.runehive.util.RandomGen.random | ( | double[] | array | ) |
Pseudo-randomly retrieves an double from this array.
| array | the array to retrieve an double from. |
double retrieved from the array. Definition at line 142 of file RandomGen.java.
References random.
| float com.runehive.util.RandomGen.random | ( | float[] | array | ) |
Pseudo-randomly retrieves an float from this array.
| array | the array to retrieve an float from. |
float retrieved from the array. Definition at line 169 of file RandomGen.java.
References random.
| int com.runehive.util.RandomGen.random | ( | int[] | array | ) |
Pseudo-randomly retrieves an int from this array.
| array | the array to retrieve an int from. |
int retrieved from the array. Definition at line 124 of file RandomGen.java.
References random.
|
package |
Pseudo-randomly retrieves a element from list.
| list | the list to retrieve an element from. |
Definition at line 196 of file RandomGen.java.
References random.
| long com.runehive.util.RandomGen.random | ( | long[] | array | ) |
Pseudo-randomly retrieves an long from this array.
| array | the array to retrieve an long from. |
long retrieved from the array. Definition at line 133 of file RandomGen.java.
References random.
| short com.runehive.util.RandomGen.random | ( | short[] | array | ) |
Pseudo-randomly retrieves an short from this array.
| array | the array to retrieve an short from. |
short retrieved from the array. Definition at line 151 of file RandomGen.java.
References random.
|
package |
Pseudo-randomly retrieves a element from array.
| array | the array to retrieve an element from. |
Definition at line 115 of file RandomGen.java.
References random.
| int com.runehive.util.RandomGen.randomIndex | ( | Object[] | array | ) |
Pseudo-randomly retrieves an index from array.
| array | the array to retrieve an index from. |
Definition at line 106 of file RandomGen.java.
References random.
| boolean[] com.runehive.util.RandomGen.shuffle | ( | boolean[] | array | ) |
An implementation of the Fisher-Yates shuffle algorithm that will shuffle the elements of an boolean array.
| array | the array that will be shuffled. |
Definition at line 318 of file RandomGen.java.
References random.
| byte[] com.runehive.util.RandomGen.shuffle | ( | byte[] | array | ) |
An implementation of the Fisher-Yates shuffle algorithm that will shuffle the elements of an byte array.
| array | the array that will be shuffled. |
Definition at line 286 of file RandomGen.java.
References random.
| char[] com.runehive.util.RandomGen.shuffle | ( | char[] | array | ) |
An implementation of the Fisher-Yates shuffle algorithm that will shuffle the elements of an char array.
| array | the array that will be shuffled. |
Definition at line 333 of file RandomGen.java.
References random.
| double[] com.runehive.util.RandomGen.shuffle | ( | double[] | array | ) |
An implementation of the Fisher-Yates shuffle algorithm that will shuffle the elements of an double array.
| array | the array that will be shuffled. |
Definition at line 254 of file RandomGen.java.
References random.
| float[] com.runehive.util.RandomGen.shuffle | ( | float[] | array | ) |
An implementation of the Fisher-Yates shuffle algorithm that will shuffle the elements of an float array.
| array | the array that will be shuffled. |
Definition at line 302 of file RandomGen.java.
References random.
| int[] com.runehive.util.RandomGen.shuffle | ( | int[] | array | ) |
An implementation of the Fisher-Yates shuffle algorithm that will shuffle the elements of an int array.
| array | the array that will be shuffled. |
Definition at line 222 of file RandomGen.java.
References random.
| long[] com.runehive.util.RandomGen.shuffle | ( | long[] | array | ) |
An implementation of the Fisher-Yates shuffle algorithm that will shuffle the elements of an long array.
| array | the array that will be shuffled. |
Definition at line 238 of file RandomGen.java.
References random.
| short[] com.runehive.util.RandomGen.shuffle | ( | short[] | array | ) |
An implementation of the Fisher-Yates shuffle algorithm that will shuffle the elements of an short array.
| array | the array that will be shuffled. |
Definition at line 270 of file RandomGen.java.
References random.
|
package |
An implementation of the Fisher-Yates shuffle algorithm that will shuffle the elements of an T array.
| array | the array that will be shuffled. |
Definition at line 206 of file RandomGen.java.
References random.
| boolean com.runehive.util.RandomGen.success | ( | double | value | ) |
Determines if a pseudorandomly generated double rounded to two decimal places is below or equal to value.
| value | the value to determine this for. |
true if successful, false otherwise. Definition at line 349 of file RandomGen.java.
References random.
|
private |
The backing ThreadLocalRandom that will pseudorandomly generate numbers.
It is generally preferred to use this over Random because although Random is thread safe; the same seed is shared concurrently, which leads to contention between multiple threads and overhead as a result of that. Surprisingly because of the way that ThreadLocalRandom works, even in completely single-threaded situations it runs up to three times faster than Random.
Definition at line 31 of file RandomGen.java.
Referenced by floatRandom(), get(), inclusive(), random(), random(), random(), random(), random(), random(), random(), random(), random(), random(), randomIndex(), shuffle(), shuffle(), shuffle(), shuffle(), shuffle(), shuffle(), shuffle(), shuffle(), shuffle(), and success().