Contents
- Description
- Field Summary
- Constructor Summary
- Method Summary
- Field Details
- Constructor Details
- Method Details
- roll(int, T[], int[])
- rollInt(int, int[], int[])
- getSecureRandom()
- selectRandom(T[], Random)
- selectRandomOrNull(T[], Random)
- selectRandomOrDefault(T[], T, Random)
- selectRandom(List)
- selectRandom(List, Random)
- randomInteger(Integer, Integer, int, RandomGenerator)
- randomFloat(Float, Float, float, RandomGenerator)
- randomDouble(Double, Double, double, RandomGenerator)
Class RandomUtil
java.lang.Object
com.hypixel.hytale.common.util.RandomUtil
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic SecureRandomstatic doublerandomDouble(Double min, Double max, double defaultValue, RandomGenerator random) Generates a random double within a specified range, returning a default value if the range is not defined, or the "max" value if the range is invalid (min bound is greater or equal to the max bound).static floatrandomFloat(Float min, Float max, float defaultValue, RandomGenerator random) Generates a random float within a specified range, returning a default value if the range is not defined, or the "max" value if the range is invalid (min bound is greater or equal to the max bound).static intrandomInteger(Integer min, Integer max, int defaultValue, RandomGenerator random) Generates a random integer within a specified range, returning a default value if the range is not defined, or the "max" value if the range is invalid (min bound is greater or equal to the max bound).static <T> Troll(int roll, T[] data, int[] chances) static introllInt(int roll, int[] data, int[] chances) static <T> TselectRandom(List<? extends T> list) static <T> TselectRandom(List<? extends T> list, Random random) static <T> TselectRandom(T[] arr, Random random) static <T> TselectRandomOrDefault(T[] arr, T defaultValue, Random random) Selects a random element from the given array, or returns the default value if the array is empty.static <T> TselectRandomOrNull(T[] arr, Random random)
-
Field Details
-
SECURE_RANDOM
-
-
Constructor Details
-
RandomUtil
public RandomUtil()
-
-
Method Details
-
roll
public static <T> T roll(int roll, T[] data, @Nonnull int[] chances) -
rollInt
public static int rollInt(int roll, int[] data, @Nonnull int[] chances) -
getSecureRandom
-
selectRandom
-
selectRandomOrNull
-
selectRandomOrDefault
@Nonnull public static <T> T selectRandomOrDefault(@Nonnull T[] arr, @Nonnull T defaultValue, @Nonnull Random random) Selects a random element from the given array, or returns the default value if the array is empty.- Type Parameters:
T- The type of the elements in the array.- Parameters:
arr- The array from which to select a random element. Must not be null.defaultValue- The default value to return if the array is empty. Must not be null.random- The random generator used to select the random element. Must not be null.- Returns:
- A randomly selected element from the array, or the default value if the array is empty.
-
selectRandom
-
selectRandom
-
randomInteger
public static int randomInteger(@Nullable Integer min, @Nullable Integer max, int defaultValue, @Nonnull RandomGenerator random) Generates a random integer within a specified range, returning a default value if the range is not defined, or the "max" value if the range is invalid (min bound is greater or equal to the max bound).- Parameters:
min- The minimum bound of the range (inclusive). Can be null, which will result in the default value being returned.max- The maximum bound of the range (exclusive). Can be null, which will result in the default value being returned.defaultValue- The default value to return if either bound is null or the range is invalid.random- The random generator used to generate the random integer. Must not be null.- Returns:
- A randomly generated integer within the specified range, or the default value if either bound is null.
-
randomFloat
public static float randomFloat(@Nullable Float min, @Nullable Float max, float defaultValue, @Nonnull RandomGenerator random) Generates a random float within a specified range, returning a default value if the range is not defined, or the "max" value if the range is invalid (min bound is greater or equal to the max bound).- Parameters:
min- The minimum bound of the range (inclusive). Can be null, which will result in the default value being returned.max- The maximum bound of the range (exclusive). Can be null, which will result in the default value being returned.defaultValue- The default value to return if either bound is null or the range is invalid.random- The random generator used to generate the random float. Must not be null.- Returns:
- A randomly generated float within the specified range, or the default value if either bound is null.
-
randomDouble
public static double randomDouble(@Nullable Double min, @Nullable Double max, double defaultValue, @Nonnull RandomGenerator random) Generates a random double within a specified range, returning a default value if the range is not defined, or the "max" value if the range is invalid (min bound is greater or equal to the max bound).- Parameters:
min- The minimum bound of the range (inclusive). Can be null; if so, the default value is returned.max- The maximum bound of the range (exclusive). Can be null; if so, the default value is returned.defaultValue- The default value to return if either bound is null.random- The random generator used to generate the random double. Must not be null.- Returns:
- A randomly generated double within the specified range, or the default value if either bound is null.
-