Weighted
interface Weighted
Represents an object that has an associated weight used for weighted random selection.
Classes implementing this interface can be used directly with methods like RandomSelector.fromWeightedIterable, where the weight of the object determines its likelihood of being selected.
Example
enum class Rarity(override val weight: Double) : Weighted {
COMMON(1.0),
UNCOMMON(0.5),
RARE(0.1)
}
val selector = RandomSelector.fromWeightedIterable(Rarity.entries)
println(selector.pick()) // Outputs a random Rarity based on the weights
Content copied to clipboard