public class RandomHelper
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.util.Random |
rand
Deprecated.
|
Constructor and Description |
---|
RandomHelper() |
Modifier and Type | Method and Description |
---|---|
static int |
getFortuneAmount(int fortune)
Gets a random amount of items to drop from a Fortune enchantment.
|
static java.util.Random |
getRandom()
Get the instance of random.
|
static boolean |
getRandomChance()
Randomly returns true or false with even distribution.
|
static boolean |
getRandomChance(double chance)
Randomly returns true or false, using a specific chance (0 to 1) of being true.
|
static boolean |
getRandomChance(float chance)
Randomly returns true or false, using a specific chance (0 to 1) of being true.
|
static boolean |
getRandomChance(int chance)
Randomly returns true or false, using a specific chance (0 to 100) of being true.
|
static boolean |
getRandomChance(java.util.Random random,
int chance)
Randomly returns true or false, using a specific chance (0 to 100) of being true.
|
static int[] |
getRandomDistinctNumbersBetween(int min,
int max,
int numElements)
Chooses a set of random numbers between min and max, inclusive.
|
static <T> T |
getRandomElementExcluding(T[] elements,
T... excluded) |
static <T> T |
getRandomElementFromArray(T... array)
Gets a random element from an array.
|
static <T> T |
getRandomElementFromCollection(java.util.Collection<T> collection)
Gets a random element from a collection.
|
static <T> T |
getRandomElementFromList(java.util.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. |
static <T> T |
getRandomElementFromList(java.util.List<T> list)
Gets a random element from a list.
|
static java.awt.Color |
getRandomHighSaturationColor() |
static int |
getRandomIndexFromWeights(java.util.List<java.lang.Integer> weights)
Generates a random index from an array of integer weights
|
static float |
getRandomNumberBetween(float min,
float max)
Returns a random float between min and max, inclusive.
|
static int |
getRandomNumberBetween(int min,
int max)
Returns a random int between min and max, inclusive.
|
static void |
initXZSeed(java.util.Random random,
net.minecraft.world.World world,
int chunkX,
int chunkZ)
Generates a random seed from the chunk coordinates in a world.
|
static net.minecraft.util.math.vector.Vector3d |
nextSpherePoint(double radius) |
static <T> T |
removeRandomElementFromCollection(java.util.Collection<T> collection)
Removes a random element from a collection and returns it.
|
static <T> T |
removeRandomElementFromList(java.util.List<T> list)
Removes a random element from a list and returns it.
|
static java.util.Random |
staticRandomWithXZSeed(net.minecraft.world.World world,
int chunkX,
int chunkZ)
Generates a random seed from the chunk coordinates in a world.
|
static float |
useRandomForNumberBetween(java.util.Random random,
float min,
float max)
Using a specified random stream, returns a random float between min and max, inclusive.
|
static int |
useRandomForNumberBetween(java.util.Random random,
int min,
int max)
Using a specified random stream, returns a random int between min and max, inclusive.
|
@Deprecated public static final java.util.Random rand
public static <T> T getRandomElementExcluding(T[] elements, T... excluded)
public static int getRandomNumberBetween(int min, int max)
min
- The minimum number that the random number can be.max
- The maximum number that the random number can be.public static float getRandomNumberBetween(float min, float max)
min
- The minimum number that the random number can be.max
- The maximum number that the random number can be.public static int[] getRandomDistinctNumbersBetween(int min, int max, int numElements)
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.public static int useRandomForNumberBetween(java.util.Random random, int min, int max)
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.public static float useRandomForNumberBetween(java.util.Random random, float min, float max)
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.public static <T> T getRandomElementFromList(java.util.List<T> list)
list
- The list to get a random element from.@Deprecated public static <T> T getRandomElementFromList(java.util.Collection<T> collection)
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.collection
- The collection to get a random element from.public static <T> T getRandomElementFromArray(T... array)
array
- The array to get a random element from.public static <T> T removeRandomElementFromList(java.util.List<T> list)
list
- The list to remove a random element from.public static boolean getRandomChance(double chance)
chance
- The chance (0 to 1) of returning true.public static boolean getRandomChance(float chance)
chance
- The chance (0 to 1) of returning true.public static boolean getRandomChance(int chance)
chance
- The chance (0 to 100) of returning true.public static boolean getRandomChance()
public static boolean getRandomChance(java.util.Random random, int chance)
random
- The random stream of numbers to get a random number from.chance
- The chance (0 to 100) of returning true.public static int getFortuneAmount(int fortune)
fortune
- The pokemonLevel of Fortune.public static void initXZSeed(java.util.Random random, net.minecraft.world.World world, int chunkX, int chunkZ)
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.public static java.util.Random staticRandomWithXZSeed(net.minecraft.world.World world, int chunkX, int chunkZ)
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.public static int getRandomIndexFromWeights(java.util.List<java.lang.Integer> weights)
weights
- The list of weights to choose the index frompublic static java.awt.Color getRandomHighSaturationColor()
public static net.minecraft.util.math.vector.Vector3d nextSpherePoint(double radius)
public static <T> T getRandomElementFromCollection(java.util.Collection<T> collection)
collection
- The collection to get a random element from.public static <T> T removeRandomElementFromCollection(java.util.Collection<T> collection)
collection
- The collection to remove a random element from.public static java.util.Random getRandom()