Class RandomHelper

java.lang.Object
com.pixelmonmod.pixelmon.api.util.helpers.RandomHelper

public class RandomHelper extends Object
Helper methods for generating random numbers.
  • Constructor Details

    • RandomHelper

      public RandomHelper()
  • Method Details

    • getRandomElementExcluding

      @SafeVarargs public static <T> T getRandomElementExcluding(T[] elements, T... excluded)
    • getRandomNumberBetween

      public static int getRandomNumberBetween(int min, int max)
      Returns a random int between min and max, inclusive.
      Parameters:
      min - The minimum number that the random number can be.
      max - The maximum number that the random number can be.
      Returns:
      A random int between min and max, inclusive.
    • getRandomNumberBetween

      public static float getRandomNumberBetween(float min, float max)
      Returns a random float between min and max, inclusive.
      Parameters:
      min - The minimum number that the random number can be.
      max - The maximum number that the random number can be.
      Returns:
      A random float between min and max, inclusive.
    • getRandomDistinctNumbersBetween

      public static int[] getRandomDistinctNumbersBetween(int min, int max, int numElements)
      Chooses a set of random numbers between min and max, inclusive. Does not choose duplicate numbers.
      Parameters:
      min - The minimum number that a random number can be.
      max - The maximum number that a random number can be.
      numElements - The number of elements to pick.
      Returns:
      The specified number of distinct random numbers.
    • useRandomForNumberBetween

      public static int useRandomForNumberBetween(Random random, int min, int max)
      Using a specified random stream, returns a random int between min and max, inclusive.
      Parameters:
      random - The random stream of numbers to get a random number from.
      min - The minimum number that the random number can be.
      max - The maximum number that the random number can be.
      Returns:
      A random int between min and max, inclusive.
    • useRandomForNumberBetween

      public static int useRandomForNumberBetween(net.minecraft.util.RandomSource random, int min, int max)
      Using a specified random stream, returns a random int between min and max, inclusive.
      Parameters:
      random - The random stream of numbers to get a random number from.
      min - The minimum number that the random number can be.
      max - The maximum number that the random number can be.
      Returns:
      A random int between min and max, inclusive.
    • useRandomForNumberBetween

      public static float useRandomForNumberBetween(Random random, float min, float max)
      Using a specified random stream, returns a random float between min and max, inclusive.
      Parameters:
      random - The random stream of numbers to get a random number from.
      min - The minimum number that the random number can be.
      max - The maximum number that the random number can be.
      Returns:
      A random float between min and max, inclusive.
    • useRandomForNumberBetween

      public static float useRandomForNumberBetween(net.minecraft.util.RandomSource random, float min, float max)
      Using a specified random stream, returns a random float between min and max, inclusive.
      Parameters:
      random - The random stream of numbers to get a random number from.
      min - The minimum number that the random number can be.
      max - The maximum number that the random number can be.
      Returns:
      A random float between min and max, inclusive.
    • getRandomElementFromList

      public static <T> T getRandomElementFromList(List<T> list)
      Gets a random element from a list.
      Parameters:
      list - The list to get a random element from.
      Returns:
      A randomly selected element in the list, or null if the list is empty.
    • getRandomElementFromList

      @Deprecated public static <T> T getRandomElementFromList(Collection<T> collection)
      Deprecated.
      use getRandomElementFromCollection(Collection), This needs to be removed immediately as it interferes with getRandomElementFromList(List) which has an optimization of direct List#get(int) compared to the Collection class.
      Gets a random element from a collection.
      Parameters:
      collection - The collection to get a random element from.
      Returns:
      A randomly selected element in the collection, or null if the collection is empty.
    • getRandomElementFromArray

      public static <T> T getRandomElementFromArray(T... array)
      Gets a random element from an array.
      Parameters:
      array - The array to get a random element from.
      Returns:
      A randomly selected element in the array, or null is the list is null or empty.
    • getRandomElementFromArray

      public static <T> T getRandomElementFromArray(net.minecraft.util.RandomSource random, T... array)
      Gets a random element from an array.
      Parameters:
      random - The random stream of numbers to get a random number from.
      array - The array to get a random element from.
      Returns:
      A randomly selected element in the array, or null is the list is null or empty.
    • removeRandomElementFromList

      public static <T> T removeRandomElementFromList(List<T> list)
      Removes a random element from a list and returns it.
      Parameters:
      list - The list to remove a random element from.
      Returns:
      A randomly removed element in the list, or null if the list is empty.
    • getRandomChance

      public static boolean getRandomChance(double chance)
      Randomly returns true or false, using a specific chance (0 to 1) of being true.
      Parameters:
      chance - The chance (0 to 1) of returning true.
      Returns:
      A randomly selected boolean value according to the chance of being true.
    • getRandomChance

      public static boolean getRandomChance(float chance)
      Randomly returns true or false, using a specific chance (0 to 1) of being true.
      Parameters:
      chance - The chance (0 to 1) of returning true.
      Returns:
      A randomly selected boolean value according to the chance of being true.
    • getRandomChance

      public static boolean getRandomChance(int chance)
      Randomly returns true or false, using a specific chance (0 to 100) of being true.
      Parameters:
      chance - The chance (0 to 100) of returning true.
      Returns:
      A randomly selected boolean value according to the chance of being true.
    • getRandomChance

      public static boolean getRandomChance()
      Randomly returns true or false with even distribution.
      Returns:
      True or false randomly with even distribution.
    • getRandomChance

      public static boolean getRandomChance(Random random, int chance)
      Randomly returns true or false, using a specific chance (0 to 100) of being true.
      Parameters:
      random - The random stream of numbers to get a random number from.
      chance - The chance (0 to 100) of returning true.
      Returns:
      A randomly selected boolean value according to the chance of being true.
    • getRandomChance

      public static boolean getRandomChance(net.minecraft.util.RandomSource random, float chance)
      Randomly returns true or false, using a specific chance (0 to 1) of being true.
      Parameters:
      random - The random stream of numbers to get a random number from.
      chance - The chance (0 to 1) of returning true.
      Returns:
      A randomly selected boolean value according to the chance of being true.
    • getFortuneAmount

      public static int getFortuneAmount(int fortune)
      Gets a random amount of items to drop from a Fortune enchantment.
      Parameters:
      fortune - The pokemonLevel of Fortune.
      Returns:
      A random amount of items to drop from the Fortune enchantment.
    • initXZSeed

      public static void initXZSeed(Random random, net.minecraft.world.level.Level world, int chunkX, int chunkZ)
      Generates a random seed from the chunk coordinates in a world. Functions the same way GenLayer does it.
      Parameters:
      random - The random object to generate a seed for.
      world - The world that the chunks are in.
      chunkX - The x chunk coordinate of the chunk used to generate the random seed.
      chunkZ - The z chunk coordinate of the chunk used to generate the random seed.
    • staticRandomWithXZSeed

      public static Random staticRandomWithXZSeed(net.minecraft.world.level.Level world, int chunkX, int chunkZ)
      Generates a random seed from the chunk coordinates in a world.
      Parameters:
      world - The world that the chunks are in.
      chunkX - The x chunk coordinate of the chunk used to generate the random seed.
      chunkZ - The z chunk coordinate of the chunk used to generate the random seed.
      Returns:
      A random stream that is seeded using the chunk coordinates.
    • getRandomIndexFromWeights

      public static int getRandomIndexFromWeights(List<Integer> weights)
      Generates a random index from an array of integer weights
      Parameters:
      weights - The list of weights to choose the index from
      Returns:
      The index chosen from the array of weights, or -1 if the weights are invalid.
    • getRandomHighSaturationColor

      public static Color getRandomHighSaturationColor()
    • nextSpherePoint

      public static net.minecraft.world.phys.Vec3 nextSpherePoint(double radius)
    • getRandomElementFromCollection

      public static <T> T getRandomElementFromCollection(Collection<T> collection)
      Gets a random element from a collection.
      Parameters:
      collection - The collection to get a random element from.
      Returns:
      A randomly selected element in the collection, or null if the collection is empty.
    • getRandomElementFromCollection

      public static <T> T getRandomElementFromCollection(net.minecraft.util.RandomSource random, Collection<T> collection)
      Gets a random element from a collection.
      Parameters:
      random - The random stream of numbers to get a random number from.
      collection - The collection to get a random element from.
      Returns:
      A randomly selected element in the collection, or null if the collection is empty.
    • removeRandomElementFromCollection

      public static <T> T removeRandomElementFromCollection(Collection<T> collection)
      Removes a random element from a collection and returns it.
      Parameters:
      collection - The collection to remove a random element from.
      Returns:
      A randomly removed element in the collection, or null if the collection is empty.
    • getRandom

      public static Random getRandom()
    • getMojangRandom

      public static net.minecraft.util.RandomSource getMojangRandom()
    • getLegacyRandom

      public static Random getLegacyRandom()