Skip to content

ProbabilityCollection

Namespace: SideXP.Core

public abstract class ProbabilityCollection

Base class for implementing lists with items bound to a probability value, and able to pick an item based on that probability value.

Properties

Items

public abstract IProbabilityItem[] Items

The items in this collection.

this[int]

public abstract IProbabilityItem this[int index]

Get an item in this collection at a given index.

Parameters

  • index: The index of the item to get.

Methods

Get()

public virtual object Get()

Gets an object from this collection picked randomly based on the probability values.

Returns

Returns the picked object

Remarks

An item with a probability of zero or less is never picked. If the collection is empty or every item has a non-positive probability, this returns false.

Get(object)

public virtual bool Get(out object data)

Gets an object from this collection picked randomly based on the probability values.

Parameters

  • data: Outputs the picked object.

Returns

Returns true if a valid object has been picked from the list successfully.

Remarks

An item with a probability of zero or less is never picked. If the collection is empty or every item has a non-positive probability, this returns false.

GetProbabilityPercents(object)

public virtual float GetProbabilityPercents(object data)

Gets the probability percentage for a given object in this collection to be picked.

Parameters

  • data: The object from this collection.

Returns

Returns the probability percentage for the given object to be picked.

Remarks

A probability of zero or less is reported as a 0% chance, consistently with Get.