Skip to content

WeightedPoolExtensions

Namespace: Shadop.Archmage.Sdk

Provides Sample and SampleIndex extension methods that draw an item from a WeightedPool at random with probability proportional to its weight, using a Random source.

public static class WeightedPoolExtensions

Inheritance ObjectWeightedPoolExtensions

Returns a randomly selected item, weighted by the pool’s weights. Throws if the pool is empty or the total weight is zero.

public static T Sample<T>(WeightedPool<T> wp, Random rng)

wp WeightedPool

rng Random

T

Returns the index of a randomly selected item, weighted by the pool’s weights. Throws if the pool is empty or the total weight is zero.

public static int SampleIndex<T>(WeightedPool<T> wp, Random rng)

wp WeightedPool

rng Random

Int32