Chance
| Type | 🔵 Class |
| Package | io.github.mrtesz.teszcore.util |
| GitHub | Chance.java |
| Package | io.github.mrtesz.teszcore.util |
| Subclasses | Chance.WeightedEntry |
Description
Util class for generating random values
Methods
roll with double
static boolean roll(double percent) throws IllegalNumberRangeException;
static boolean roll(double percent, Random random) throws IllegalNumberRangeException, NullPointerException;
Roll a boolean of a provided percent
| Parameter | Type | Annotations | Description |
|---|---|---|---|
percent | double | - | Percent |
random | <abbr title=java.util.Random>Random</abbr> | @NotNull | (optional) Random, that is used to generate nextDouble. Default: new java.util.Random() |
Returns: boolean — random.nextDouble() < percent
Throws: IllegalNumberRangeException when percent is not in the range 0.0-1.0 Throws: NullPointerException when random is null
roll with int
static boolean roll(int percent) throws IllegalNumberRangeException;
static boolean roll(int percent, Random random) throws IllegalNumberRangeException, NullPointerException;
Roll a boolean of a provided percent
| Parameter | Type | Annotations | Description |
|---|---|---|---|
percent | int | - | Percent |
random | <abbr title=java.util.Random>Random</abbr> | @NotNull | (optional) Random, that is used to generate nextDouble. Default: new java.util.Random() |
Returns: boolean — roll((double) percent / 100)
Throws: IllegalNumberRangeException when percent is not in the range 0-100 Throws: NullPointerException when random is null
roll with Collection<? extends WeightedEntry<T>>
static <T> T roll(Collection<? extends WeightedEntry<T>> entries);
static <T> T roll(Collection<? extends WeightedEntry<T>> entries, Random random);
Roll an Object from a collection of WeightedEntries
| Parameter | Type | Annotations | Description |
|---|---|---|---|
entries | Collection<? extends WeightedEntry<T>> | @NotNull | WeightedEntries to roll from |
random | <abbr title=java.util.Random>Random</abbr> | @NotNull | (optional) Random, that is used to generate nextDouble. Default: new java.util.Random() |
Returns: T — Rolled object