Skip to content

ProbabilityList<T>

Namespace: SideXP.Core | Inherits from: ProbabilityCollection, IList<ProbabilityList<T>.ProbabilityItem>

public class ProbabilityList<T> : ProbabilityCollection, IList<ProbabilityList<T>.ProbabilityItem>

Represents a list of items bound to a probabiility value, from which those items can be picked randomly by taking account of their probability.

Type parameters

  • T: The type of data bound to probability values.

Properties

Items

public override IProbabilityItem[] Items

The items in this collection.

Count

public int Count

Inherited documentation.

IsReadOnly

public bool IsReadOnly

Inherited documentation.

this[int]

public override IProbabilityItem this[int index]

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

Methods

Get(T)

public bool Get(out T 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(T)

public float GetProbabilityPercents(T 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.

IndexOf(ProbabilityItem)

public int IndexOf(ProbabilityItem item)

Inherited documentation.

Insert(int, ProbabilityItem)

public void Insert(int index, ProbabilityItem item)

Inherited documentation.

RemoveAt(int)

public void RemoveAt(int index)

Inherited documentation.

Add(ProbabilityItem)

public void Add(ProbabilityItem item)

Inherited documentation.

Clear()

public void Clear()

Inherited documentation.

Contains(ProbabilityItem)

public bool Contains(ProbabilityItem item)

Inherited documentation.

CopyTo(ProbabilityItem[], int)

public void CopyTo(ProbabilityItem[] array, int arrayIndex)

Inherited documentation.

Remove(ProbabilityItem)

public bool Remove(ProbabilityItem item)

Inherited documentation.

GetEnumerator()

public IEnumerator<ProbabilityItem> GetEnumerator()

Iterates through the items in this collection.