Class ProbabilityNormalizer
Provides a static utility method for normalizing a collection of ProbabilityEntry<T> objects so that the enabled entries' probabilities collectively sum to 1.0.
Inherited Members
Namespace: Scylla.Core.Util.Random
Assembly: ScyllaCore.dll
Syntax
public static class ProbabilityNormalizer
Remarks
Locked entries are excluded from scaling and their probabilities are subtracted from the available probability mass (1.0) before the remaining mass is distributed among the unlocked entries proportionally.
This class is used internally by Normalize() and by the FromProbabilities(T[], float[]) factory method.
Methods
Normalize<T>(List<ProbabilityEntry<T>>)
Normalizes the probabilities of all enabled, unlocked entries in-place so that the combined probability of all enabled entries (locked and unlocked) sums to 1.0.
Declaration
public static void Normalize<T>(List<ProbabilityEntry<T>> entries)
Parameters
| Type | Name | Description |
|---|---|---|
| List<ProbabilityEntry<T>> | entries | The list of ProbabilityEntry<T> objects to normalize in-place. Null or empty lists are silently ignored. |
Type Parameters
| Name | Description |
|---|---|
| T | The item type of the probability entries. |
Remarks
Algorithm:
- Sum the probabilities of all enabled locked entries (
lockedSum). - Compute the remainder available for unlocked entries:
remainder = 1.0 - lockedSum. - If the locked entries exceed 1.0,
entriesentries receive zero probability and a warning is logged. - If all unlocked probabilities are zero, the remainder is distributed evenly.
- Otherwise, unlocked probabilities are scaled by
remainder / unlockedSum.
Disabled entries are never read or modified.