WeightedPool<T>
Namespace: Shadop.Archmage.Sdk
Holds items alongside their selection weights in two parallel arrays of equal length.
The Sample and SampleIndex extension methods (in
WeightedPoolExtensions) draw an item at random with probability
proportional to its weight. The SampleWith and SampleIndexWith
methods map a caller-supplied value to an item deterministically according to the weights.
public class WeightedPool<T>Inheritance Object → WeightedPool
Properties
Section titled “Properties”The candidate values, one per weight.
public T[] Items { get; set; }Property Value
Section titled “Property Value”T[]
Weights
Section titled “Weights”The non-negative selection weights, parallel to WeightedPool
public Int32[] Weights { get; set; }Property Value
Section titled “Property Value”The number of items in the pool.
public int Count { get; }Property Value
Section titled “Property Value”Constructors
Section titled “Constructors”WeightedPool()
Section titled “WeightedPool()”public WeightedPool()WeightedPool(T[], Int32[])
Section titled “WeightedPool(T[], Int32[])”public WeightedPool(T[] items, Int32[] weights)Parameters
Section titled “Parameters”items T[]
weights Int32[]
Methods
Section titled “Methods”SampleWith(Single)
Section titled “SampleWith(Single)”Maps the value to an item deterministically according to the weights.
value < 0 returns the first item with non-zero weight; value >= 1
returns the last. Throws if the pool is empty or the total weight is zero.
public T SampleWith(float value)Parameters
Section titled “Parameters”value Single
Returns
Section titled “Returns”T
SampleIndexWith(Single)
Section titled “SampleIndexWith(Single)”Maps the value to an item index deterministically according to the weights.
value < 0 returns the first item index with non-zero weight; value >= 1
returns the last. Throws if the pool is empty or the total weight is zero.
public int SampleIndexWith(float value)Parameters
Section titled “Parameters”value Single