Skip to content

UnityWeightedPoolExtensions

Namespace: Shadop.Archmage.Sdk

Extension methods for WeightedPool<T>.

public static class UnityWeightedPoolExtensions

Inheritance ObjectUnityWeightedPoolExtensions

Returns a randomly selected item, with each item’s probability proportional to its weight. Uses Unity’s global UnityEngine.Random.

Throws if the pool is empty or the total weight is zero.

public static T Sample<T>(this WeightedPool<T> wp)

T
The randomly selected item.


Returns the index of a randomly selected item, with each item’s probability proportional to its weight. Uses Unity’s global UnityEngine.Random.

Throws if the pool is empty or the total weight is zero.

public static int SampleIndex<T>(this WeightedPool<T> wp)

Int32
The zero-based index of the randomly selected item.