Class RandomUtil

java.lang.Object
com.hypixel.hytale.common.util.RandomUtil

public class RandomUtil extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
     
    static double
    randomDouble(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 float
    randomFloat(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 int
    randomInteger(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> T
    roll(int roll, T[] data, int[] chances)
     
    static int
    rollInt(int roll, int[] data, int[] chances)
     
    static <T> T
    selectRandom(List<? extends T> list)
     
    static <T> T
    selectRandom(List<? extends T> list, Random random)
     
    static <T> T
    selectRandom(T[] arr, Random random)
     
    static <T> T
    selectRandomOrDefault(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> T
    selectRandomOrNull(T[] arr, Random random)
     

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • 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

      public static SecureRandom getSecureRandom()
    • selectRandom

      public static <T> T selectRandom(@Nonnull T[] arr, @Nonnull Random random)
    • selectRandomOrNull

      @Nullable public static <T> T selectRandomOrNull(@Nonnull T[] arr, @Nonnull Random random)
    • 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

      public static <T> T selectRandom(@Nonnull List<? extends T> list)
    • selectRandom

      public static <T> T selectRandom(@Nonnull List<? extends T> list, @Nonnull Random random)
    • 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.