Contents
- Description
- Method Summary
- Method Details
- randomBinomial()
- randomRange(double[])
- randomRange(double, double)
- randomRange(float[])
- randomRange(float, float)
- randomRange(int)
- randomRange(int[])
- randomRange(int, int)
- randomRange(long, long)
- randomDuration(Duration, Duration)
- randomBoolean()
- randomElement(List)
- jitter(Vector3d, double)
- randomWeightedElement(Collection, ToDoubleFunction)
- randomWeightedElement(Collection, ToDoubleFunction, double)
- randomIntWeightedElement(Collection, ToIntFunction)
- randomIntWeightedElement(Collection, ToIntFunction, int)
- randomWeightedElementFiltered(Collection, Predicate, ToIntFunction)
- randomWeightedElementFiltered(Collection, Predicate, ToIntFunction, int)
- randomWeightedElement(Collection, Predicate, ToDoubleFunction)
- randomWeightedElement(Collection, Predicate, ToDoubleFunction, double)
- randomWeightedElement(Collection, BiPredicate, ToDoubleBiFunction, double, U)
- reservoirSample(List, Predicate, int, List)
- reservoirSample(S, TriFunction, int, T, G, H)
- reservoirSample(E, int, T)
- reservoirSample(int, int, int[])
- pickWeightedIndex(double[])
Class RandomExtra
java.lang.Object
com.hypixel.hytale.math.random.RandomExtra
-
Method Summary
Modifier and TypeMethodDescriptionstatic org.joml.Vector3djitter(org.joml.Vector3d vec, double maxRange) static intpickWeightedIndex(double[] weights) Pick a random weighted index based on an array of weightsstatic doublestatic booleanstatic DurationrandomDuration(Duration from, Duration to) static <T> TrandomElement(List<T> collection) static <T> TrandomIntWeightedElement(Collection<? extends T> elements, ToIntFunction<T> weight) Pick a random element from a collection of weighted elements.static <T> TrandomIntWeightedElement(Collection<? extends T> elements, ToIntFunction<T> weight, int sumWeights) Pick a random element from a collection of weighted elements using a known fixed sum of weights.static doublerandomRange(double[] range) static doublerandomRange(double from, double to) static floatrandomRange(float[] range) static floatrandomRange(float from, float to) static intrandomRange(int bound) static intrandomRange(int[] range) static intrandomRange(int from, int to) static longrandomRange(long from, long to) static <T,U> T randomWeightedElement(Collection<? extends T> elements, BiPredicate<T, U> filter, ToDoubleBiFunction<T, U> weight, double sumWeights, U meta) static <T> TrandomWeightedElement(Collection<? extends T> elements, Predicate<T> filter, ToDoubleFunction<T> weight) Pick a random element from a collection of weighted elements filtering unwanted elements.static <T> TrandomWeightedElement(Collection<? extends T> elements, Predicate<T> filter, ToDoubleFunction<T> weight, double sumWeights) Pick a random element from a collection of weighted elements filtering unwanted elements using a known fixed sum of weights.static <T> TrandomWeightedElement(Collection<? extends T> elements, ToDoubleFunction<T> weight) Pick a random element from a collection of weighted elements.static <T> TrandomWeightedElement(Collection<? extends T> elements, ToDoubleFunction<T> weight, double sumWeights) Pick a random element from a collection of weighted elements using a known fixed sum of weights.static <T> TrandomWeightedElementFiltered(Collection<? extends T> elements, Predicate<T> filter, ToIntFunction<T> weight) Pick a random element from a collection of weighted elements filtering unwanted elements.static <T> TrandomWeightedElementFiltered(Collection<? extends T> elements, Predicate<T> filter, ToIntFunction<T> weight, int sumWeights) Pick a random element from a collection of weighted elements filtering unwanted elements using a known fixed sum of weights.static intreservoirSample(int n, int count, int[] out) Pick a random sample of indices from a fixed-size index space, writing the result into a reused buffer.static <E, T extends List<E>>
voidreservoirSample(E element, int count, T picked) Pick a random sample from a collection of elements where the actual number of matching elements is unknown.static <T> voidreservoirSample(List<T> input, Predicate<T> matcher, int count, List<T> picked) Pick a random sample from a collection of elements where the actual number of matching elements is unknown.reservoirSample(S input, TriFunction<E, G, H, F> filter, int count, T picked, G g, H h) Pick a random sample from a collection of elements where the actual number of matching elements is unknown.
-
Method Details
-
randomBinomial
public static double randomBinomial() -
randomRange
public static double randomRange(@Nonnull double[] range) -
randomRange
public static double randomRange(double from, double to) -
randomRange
public static float randomRange(@Nonnull float[] range) -
randomRange
public static float randomRange(float from, float to) -
randomRange
public static int randomRange(int bound) -
randomRange
public static int randomRange(@Nonnull int[] range) -
randomRange
public static int randomRange(int from, int to) -
randomRange
public static long randomRange(long from, long to) -
randomDuration
-
randomBoolean
public static boolean randomBoolean() -
randomElement
-
jitter
@Nonnull public static org.joml.Vector3d jitter(@Nonnull org.joml.Vector3d vec, double maxRange) -
randomWeightedElement
@Nullable public static <T> T randomWeightedElement(@Nonnull Collection<? extends T> elements, @Nonnull ToDoubleFunction<T> weight) Pick a random element from a collection of weighted elements.- Type Parameters:
T- type of element- Parameters:
elements- the collection of elementsweight- function returning weight of element- Returns:
- randomly chosen element
-
randomWeightedElement
@Nullable public static <T> T randomWeightedElement(@Nonnull Collection<? extends T> elements, @Nonnull ToDoubleFunction<T> weight, double sumWeights) Pick a random element from a collection of weighted elements using a known fixed sum of weights.Use this function when sum of weights is known.
- Type Parameters:
T- type of element- Parameters:
elements- the collection of elementsweight- function returning weight of elementsumWeights- sum of weights- Returns:
- randomly chosen element
-
randomIntWeightedElement
@Nullable public static <T> T randomIntWeightedElement(@Nonnull Collection<? extends T> elements, @Nonnull ToIntFunction<T> weight) Pick a random element from a collection of weighted elements.- Type Parameters:
T- type of element- Parameters:
elements- the collection of elementsweight- function returning weight of element- Returns:
- randomly chosen element
-
randomIntWeightedElement
@Nullable public static <T> T randomIntWeightedElement(@Nonnull Collection<? extends T> elements, @Nonnull ToIntFunction<T> weight, int sumWeights) Pick a random element from a collection of weighted elements using a known fixed sum of weights.Use this function when sum of weights is known.
- Type Parameters:
T- type of element- Parameters:
elements- the collection of elementsweight- function returning weight of elementsumWeights- sum of weights- Returns:
- randomly chosen element
-
randomWeightedElementFiltered
@Nullable public static <T> T randomWeightedElementFiltered(@Nonnull Collection<? extends T> elements, @Nonnull Predicate<T> filter, @Nonnull ToIntFunction<T> weight) Pick a random element from a collection of weighted elements filtering unwanted elements.- Type Parameters:
T- type of element- Parameters:
elements- the collection of elementsfilter- predicate return false for elements to ignoreweight- function returning weight of element- Returns:
- randomly chosen element
-
randomWeightedElementFiltered
@Nullable public static <T> T randomWeightedElementFiltered(@Nonnull Collection<? extends T> elements, @Nonnull Predicate<T> filter, @Nonnull ToIntFunction<T> weight, int sumWeights) Pick a random element from a collection of weighted elements filtering unwanted elements using a known fixed sum of weights.Use this function when sum of weights is known.
- Type Parameters:
T- type of element- Parameters:
elements- the collection of elementsfilter- predicate return false for elements to ignoreweight- function returning weight of elementsumWeights- sum of weights- Returns:
- randomly chosen element
-
randomWeightedElement
@Nullable public static <T> T randomWeightedElement(@Nonnull Collection<? extends T> elements, @Nonnull Predicate<T> filter, @Nonnull ToDoubleFunction<T> weight) Pick a random element from a collection of weighted elements filtering unwanted elements.- Type Parameters:
T- type of element- Parameters:
elements- the collection of elementsfilter- predicate return false for elements to ignoreweight- function returning weight of element- Returns:
- randomly chosen element
-
randomWeightedElement
@Nullable public static <T> T randomWeightedElement(@Nonnull Collection<? extends T> elements, @Nonnull Predicate<T> filter, @Nonnull ToDoubleFunction<T> weight, double sumWeights) Pick a random element from a collection of weighted elements filtering unwanted elements using a known fixed sum of weights.Use this function when sum of weights is known.
- Type Parameters:
T- type of element- Parameters:
elements- the collection of elementsfilter- predicate return false for elements to ignoreweight- function returning weight of elementsumWeights- sum of weights- Returns:
- randomly chosen element
-
randomWeightedElement
@Nullable public static <T,U> T randomWeightedElement(@Nonnull Collection<? extends T> elements, @Nonnull BiPredicate<T, U> filter, @Nonnull ToDoubleBiFunction<T, U> weight, double sumWeights, U meta) -
reservoirSample
public static <T> void reservoirSample(@Nonnull List<T> input, @Nonnull Predicate<T> matcher, int count, @Nonnull List<T> picked) Pick a random sample from a collection of elements where the actual number of matching elements is unknown.An implementation of Reservoir Sampling.
- Type Parameters:
T- type of element- Parameters:
input- the list of elements to sample frommatcher- the predicate for matching elements that are valid pickscount- the number of elements to pickpicked- an output list for placing the elements chosen in the sampling
-
reservoirSample
public static <E, S extends List<E>, F, T extends List<F>, G, H> void reservoirSample(@Nonnull S input, @Nonnull TriFunction<E, G, H, F> filter, int count, @Nonnull T picked, G g, H h) Pick a random sample from a collection of elements where the actual number of matching elements is unknown.An implementation of Reservoir Sampling.
- Parameters:
input- the list of elements to sample fromfilter- function accepting element from input list and return element for output list or null if element should not be consideredcount- the number of elements to pickpicked- an output list for placing the elements chosen in the samplingg- user provided object passed to #filterh- second user provided object passed to #filter
-
reservoirSample
Pick a random sample from a collection of elements where the actual number of matching elements is unknown.An implementation of Reservoir Sampling.
- Parameters:
element- element from input set to sample fromcount- the number of elements to pickpicked- an output list for placing the elements chosen in the sampling
-
reservoirSample
public static int reservoirSample(int n, int count, @Nonnull int[] out) Pick a random sample of indices from a fixed-size index space, writing the result into a reused buffer.An implementation of Reservoir Sampling.
- Parameters:
n- the size of the index space to sample fromcount- the number of indices to pickout- an output buffer for placing the indices chosen in the sampling- Returns:
- the number of indices written, min(count, n)
-
pickWeightedIndex
public static int pickWeightedIndex(@Nonnull double[] weights) Pick a random weighted index based on an array of weights- Parameters:
weights- an array of weights- Returns:
- a random index picked based on these weights
-