ProbabilityList<T>

If you are learning RNGNeeds from the top down, start with the guides and conceptual docs first, then come back here when you want the exact runtime shape of the main list type.

ProbabilityList<T> is the core runtime type in RNGNeeds.

It stores a list of ProbabilityItem<T> entries and provides the APIs for:

  • adding and removing items
  • managing probabilities and weights
  • picking one or many values
  • preventing repeats
  • working with seeds and pick history
  • supporting depletable lists
  • connecting influence providers

Important concepts first


Common workflow

var lootTable = new ProbabilityList<string>();

lootTable.AddItem("Potion", 0.5f);
lootTable.AddItem("Gold", 0.3f);
lootTable.AddItem("Rare Gem", 0.2f);

string reward = lootTable.PickValue();

Core properties

Core properties

PROPERTYListName
string

Optional display name for the list. This becomes especially useful when the list is used inside a PLCollection<T>, where the collection can look up and manage lists by name.

PROPERTYItemCount
int

Number of items in the list.

PROPERTYUnlockedItemsCount
int

Number of items that are not locked.

PROPERTYEnabledItemsCount
int

Number of enabled items.

PROPERTYIsListInfluenced
bool

Returns true when at least one item is affected by an influence provider.


Selection behavior

Selection settings

PROPERTYSelectionMethodID
string

Identifier of the selection method used by this list. The identifier is resolved through RNGNeeds Core.

PROPERTYPreventRepeat
PreventRepeatMethod

Controls how repeated picks are handled.

PROPERTYShuffleIterations
int

Number of shuffle passes used by PreventRepeatMethod.Shuffle. Clamped between 1 and 5.

PROPERTYPickCountMin
int

Minimum number of values selected by multi-pick methods.

PROPERTYPickCountMax
int

Maximum number of values selected by multi-pick methods.

PROPERTYLinkPickCounts
bool

When true, the effective pick count is fixed to PickCountMin.

PROPERTYMaintainPickCountIfDisabled
bool

Keeps trying to reach the desired pick count even when disabled items interfere. This can change the resulting distribution and has built-in fail-safe checks for pathological cases.

PROPERTYPickCountCurve
AnimationCurve

Controls the bias used when the pick count is randomly chosen between min and max.


Picking values

Pick methods

METHODPickValue
T PickValue()

Picks one value and returns it. If selection fails, the default value of T is returned.

METHODTryPickValue
bool TryPickValue(out T value)

Safest single-pick method when you need to distinguish failure from a valid default value.

METHODPickValues
List<T> PickValues() / overloads

Picks multiple values and returns a shared list of results.

METHODPickValueWithIndex
(T Value, int Index) PickValueWithIndex()

Picks one value and also returns the selected item index.

METHODTryPickValueWithIndex
bool TryPickValueWithIndex(out T value, out int index)

Safer version of PickValueWithIndex() when you need explicit success/failure.

METHODRunTest
TestResults RunTest()

Runs a selection test using the current configuration and returns diagnostic results.


Working with items

Item management

METHODAddItem
ProbabilityItem<T> AddItem(...) / overloads

Adds an item using a value, explicit probability, explicit weight, or an already-created ProbabilityItem<T>.

METHODAddItems
void AddItems(...) / overloads

Adds multiple values at once.

METHODRemoveItem
bool RemoveItem(...) / overloads

Removes an item by value or item reference.

METHODRemoveItemAtIndex
bool RemoveItemAtIndex(int index, bool normalize = true)

Removes an item by index.

METHODClearList
void ClearList()

Removes all items and clears history.

METHODGetProbabilityItem
ProbabilityItem<T> GetProbabilityItem(int index)

Gets the item at a specific index.

METHODTryGetProbabilityItem
bool TryGetProbabilityItem(...) / overloads

Safely retrieves an item by index or value.


Probability operations

Probability operations

METHODGetItemProbability
float GetItemProbability(int index)

Returns the effective probability currently used during selection.

METHODGetItemBaseProbability
float GetItemBaseProbability(int index)

Returns the raw stored base probability.

METHODAdjustItemBaseProbability
void AdjustItemBaseProbability(int index, float amount)

Adds a value to an item's base probability.

METHODSetItemBaseProbability
bool SetItemBaseProbability(int index, float baseProbability, bool normalize = true)

Sets an item's base probability, optionally normalizing the rest of the list.

METHODResetAllProbabilities
void ResetAllProbabilities()

Evens out probabilities of all unlocked items.

METHODNormalizeProbabilities
float NormalizeProbabilities()

Normalizes unlocked items so the list sums to 1.


Weights

Weight-based distribution helpers

PROPERTYTotalWeight
int

Sum of all item weights in the list.

PROPERTYBaseWeight
int

Reference weight used by helper methods. Clamped between 1 and 10000.

PROPERTYWeightsPriority
bool

When enabled, probabilities snap back to weight-derived fractions during certain operations.

METHODGetItemWeight
int GetItemWeight(int index)

Returns an item's current weight.

METHODSetItemWeight
void SetItemWeight(int index, int weight)

Sets an item's weight and redistributes or recalculates as needed.

METHODCalculatePercentageFromWeights
void CalculatePercentageFromWeights()

Rebuilds probabilities from weights.

METHODResetWeights
void ResetWeights()

Rebuilds weights from the current probability distribution.

METHODRecalibrateWeights
void RecalibrateWeights()

Rebalances unlocked-item weights while preserving total weight where possible.


Item state and influence

Item state and influence helpers

METHODSetItemProperties
bool SetItemProperties(int index, float baseProbability, bool enabled, bool locked)

Updates several core item properties together.

METHODSetItemEnabled / SetAllItemsEnabled
bool SetItemEnabled(int index, bool enabled)

Enables or disables one item or the whole list.

METHODSetItemLocked / SetAllItemsLocked
bool SetItemLocked(int index, bool locked)

Locks or unlocks one item or the whole list.

METHODSetItemInfluenceProvider
void SetItemInfluenceProvider(int index, IProbabilityInfluenceProvider influenceProvider)

Assigns an external influence provider to an item.

METHODSetItemInfluenceSpread
void SetItemInfluenceSpread(int index, Vector2 spread)

Controls the minimum and maximum probability range allowed under influence.

METHODSetItemInvertInfluence
void SetItemInvertInfluence(int index, bool invertInfluence)

Reverses how influence affects that item.

For the conceptual walkthrough of influence, see Probability Influence.


Seeding and history

Seeding and history

PROPERTYCurrentSeed
uint

The seed currently stored on the list.

PROPERTYSeed
uint

Returns or sets the list seed. When KeepSeed is false, RNGNeeds regenerates it before each pick.

PROPERTYKeepSeed
bool

Keeps the same seed between picks when enabled.

PROPERTYPickHistory
PickHistory

Access to the stored history of recent picks.

PROPERTYLastPickCount / LastPickedIndex / LastPickedValue
history helpers

Convenience accessors for the most recent selection.

PROPERTYLastPickedIndices / LastPickedValues
shared lists

Shared result lists representing the last pick operation.

METHODGetLastPickedIndices / GetLastPickedValues
void GetLastPicked...(List<...> listToFill)

Fills your own list instead of using the shared internal lists.

METHODSetHistoryCapacity
void SetHistoryCapacity(int capacity)

Changes the history size.

METHODClearHistory
void ClearHistory()

Clears the list's pick history.

See also PickHistory.


Depletable lists

Depletable list helpers

PROPERTYIsDepletable
bool

Enables depletion behavior for the list.

METHODRefillItems
void RefillItems()

Refills all item units back to their max values.

METHODSetAllItemsUnits
void SetAllItemsUnits(int units)

Sets the current units of all items.

METHODSetAllItemsMaxUnits
void SetAllItemsMaxUnits(int units)

Sets the maximum units of all items.

METHODSetAllItemsDepletable / SetAllItemsDepletableProperties
bulk depletion helpers

Configures depletion behavior across all items.

METHODSetItemDepletable
void SetItemDepletable(int index, bool depletable = true, int units = 1, int maxUnits = 1)

Configures depletion for one item.

METHODGetTotalUnits / GetTotalMaxUnits
int GetTotal...()

Returns aggregate depletion information for enabled depletable items.