Class RandomUtils
java.lang.Object
com.blackrook.gloop.openal.struct.RandomUtils
Utility class for random generation.
- Author:
- Matthew Tropiano
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanpercentChance(Random rand, int percent) Calculates a percent chance of something occurring.static intReturns a random integer from 0 (inclusive) to x (exclusive).static intReturns a random integer from base to base+range.static booleanrandBoolean(Random rand) Returns a random boolean.static byteReturns a random byte value.static voidFills an array with random byte values.static charrandChar(Random rand, CharSequence chars) Returns a random character in a string.static doublerandDouble(Random rand) static doublerandDouble(Random rand, double lo, double hi) Returns a random double from lo to hi (inclusive).static doublerandDoubleN(Random rand) Returns a random double value from -1 to 1 (inclusive).static <T> TrandElement(Random rand, T... objects) Returns a random entry in an array/list.static floatstatic floatReturns a random float from lo to hi (inclusive).static floatrandFloatN(Random rand) Returns a random float value from -1 to 1 (inclusive).static doublestatic floatrandGaussFloat(Random rand) Returns a random Gaussian-distributed float value from -inf to +inf.static floatrandGaussFloat(Random rand, float lo, float hi) Returns a random Gaussian float from lo to hi (inclusive).static intstatic intReturns a random integer from lo to hi (inclusive).static longstatic shortReturns a random short from lo to hi (inclusive).static shortReturns a random short from lo to hi (inclusive).static StringrandString(Random rand, String alphabet, int length) Generates a string of random characters from a provided alphabet.static intRolls a die.static intRolls a die many times.
-
Method Details
-
randBoolean
Returns a random boolean.- Parameters:
rand- the random number generator.- Returns:
- true or false.
-
randByte
Returns a random byte value.- Parameters:
rand- the random number generator.- Returns:
- a value from 0 to 255.
-
randInt
- Parameters:
rand- the random number generator.- Returns:
- a random integer.
-
randLong
- Parameters:
rand- the random number generator.- Returns:
- a random long.
-
randFloat
- Parameters:
rand- the random number generator.- Returns:
- a random float value from [0 to 1) (inclusive/exclusive).
-
randDouble
- Parameters:
rand- the random number generator.- Returns:
- a random double value from [0 to 1) (inclusive/exclusive).
-
randGauss
- Parameters:
rand- the random number generator.- Returns:
- a random Gaussian-distributed double value from -inf to +inf.
-
randBytes
Fills an array with random byte values.- Parameters:
rand- the random number generator.b- the output array to fill with bytes.
-
rand
Returns a random integer from 0 (inclusive) to x (exclusive).- Parameters:
rand- the random number generator.x- the upper bound.- Returns:
- the next integer.
-
rand
Returns a random integer from base to base+range.- Parameters:
rand- the random number generator.base- the lower bound.range- the upper bound (inclusive) of how much to add to the lower bound.- Returns:
- the next integer.
-
randFloat
Returns a random float from lo to hi (inclusive).- Parameters:
rand- the random number generator.lo- the lower bound.hi- the upper bound.- Returns:
- the next float.
-
randGaussFloat
Returns a random Gaussian-distributed float value from -inf to +inf.- Parameters:
rand- the random number generator.- Returns:
- the next float.
-
randGaussFloat
Returns a random Gaussian float from lo to hi (inclusive).- Parameters:
rand- the random number generator.lo- the lower bound.hi- the upper bound.- Returns:
- the next float.
-
randInt
Returns a random integer from lo to hi (inclusive).- Parameters:
rand- the random number generator.lo- the lower bound.hi- the upper bound.- Returns:
- the next float.
-
randFloatN
Returns a random float value from -1 to 1 (inclusive).- Parameters:
rand- the random number generator.- Returns:
- the next float.
-
randDouble
Returns a random double from lo to hi (inclusive).- Parameters:
rand- the random number generator.lo- the lower bound.hi- the upper bound.- Returns:
- the next double.
-
randDoubleN
Returns a random double value from -1 to 1 (inclusive).- Parameters:
rand- the random number generator.- Returns:
- the next double.
-
randShort
Returns a random short from lo to hi (inclusive).- Parameters:
rand- the random number generator.lo- the lower bound.hi- the upper bound.- Returns:
- the next short.
-
randShort
Returns a random short from lo to hi (inclusive).- Parameters:
rand- the random number generator.lo- the lower bound.hi- the upper bound.- Returns:
- the next short.
-
randChar
Returns a random character in a string.- Parameters:
rand- the Random instance to use.chars- the characters to sample.- Returns:
- a random character.
-
randString
Generates a string of random characters from a provided alphabet.- Parameters:
rand- the random number generator.alphabet- the source alphabet (cannot be null).length- the amount of characters to generate.- Returns:
- a string of sampled characters.
-
randElement
Returns a random entry in an array/list.- Type Parameters:
T- the array object type.- Parameters:
rand- the Random instance to use.objects- the array of objects to select from.- Returns:
- a random entry from the array.
-
percentChance
Calculates a percent chance of something occurring.- Parameters:
rand- the random number generator.percent- the chance from 0 to 100.- Returns:
- true if happening, false otherwise.
-
roll
Rolls a die.- Parameters:
rand- the random number generator.die- size of the die.- Returns:
- the outcome.
-
roll
Rolls a die many times. Example: 2d20 = roll(rand,2,20)- Parameters:
rand- the random number generator.n- times to roll.die- size of the die.- Returns:
- the outcome total.
-