Package io.github.mrtesz.teszcore.util
Class Chance
java.lang.Object
io.github.mrtesz.teszcore.util.Chance
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA weighted entry holding a chance and a result value, used inroll(Collection). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanroll(double percent) Rolls a `boolean` of a provided percentagestatic booleanRolls a `boolean` of a provided percentage with a specified randomstatic booleanroll(int percent) Rolls a percentagestatic booleanRolls a percentage with a specified randomstatic <T> Troll(@NotNull Collection<? extends Chance.WeightedEntry<T>> entries) Roll a value of a weighted entry collectionstatic <T> Troll(@NotNull Collection<? extends Chance.WeightedEntry<T>> entries, @NotNull Random random) Roll a value of a weighted entry collection with a specified random
-
Constructor Details
-
Chance
public Chance()
-
-
Method Details
-
roll
Rolls a `boolean` of a provided percentage- Parameters:
percent- percent- Returns:
- the rolled result
- Throws:
IllegalNumberRangeException- ifpercentis not in the range 0.0-1.0
-
roll
public static boolean roll(double percent, @NotNull @NotNull Random random) throws IllegalNumberRangeException, NullPointerException Rolls a `boolean` of a provided percentage with a specified random- Parameters:
percent- percentrandom- random- Returns:
- the rolled result
- Throws:
IllegalNumberRangeException- ifpercentis not in the range 0.0-1.0NullPointerException- ifrandomis null
-
roll
Rolls a percentage- Parameters:
percent- percent- Returns:
- the rolled result
- Throws:
IllegalArgumentException- ifpercentis not in the range 0-100IllegalNumberRangeException
-
roll
public static boolean roll(int percent, @NotNull @NotNull Random random) throws IllegalNumberRangeException, NullPointerException Rolls a percentage with a specified random- Parameters:
percent- percentrandom- random- Returns:
- the rolled result
- Throws:
IllegalArgumentException- ifpercentis not in the range 0-100NullPointerException- ifrandomis nullIllegalNumberRangeException
-
roll
Roll a value of a weighted entry collection- Parameters:
entries- entries- Returns:
- rolled value
-
roll
public static <T> T roll(@NotNull @NotNull Collection<? extends Chance.WeightedEntry<T>> entries, @NotNull @NotNull Random random) Roll a value of a weighted entry collection with a specified random- Parameters:
entries- entriesrandom- random- Returns:
- rolled value
-