Chance

  
Type🔵 Class
Packageio.github.mrtesz.teszcore.util
GitHubChance.java
Packageio.github.mrtesz.teszcore.util
SubclassesChance.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

ParameterTypeAnnotationsDescription
percentdouble-Percent
random<abbr title=java.util.Random>Random</abbr>@NotNull(optional) Random, that is used to generate nextDouble. Default: new java.util.Random()

Returns: booleanrandom.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

ParameterTypeAnnotationsDescription
percentint-Percent
random<abbr title=java.util.Random>Random</abbr>@NotNull(optional) Random, that is used to generate nextDouble. Default: new java.util.Random()

Returns: booleanroll((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

ParameterTypeAnnotationsDescription
entriesCollection<? extends WeightedEntry<T>>@NotNullWeightedEntries 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



Table of contents


Back to top

Copyright © 2026 Mr_Tesz. All rights reserved

This site uses Just the Docs, a documentation theme for Jekyll.