Skip to main content

WeightedRandomList

This interface defines the contract for a weighted random list, allowing retrieval of elements based on their assigned weights. It provides methods to get a single weighted random element, get an element with a specific seed, list all elements, and get the total number of elements.

Methods


Get()

@classmethod
def Get() - > Comparable

Retrieves a randomly selected item from the list, weighted by its assigned probability. Callers use this to get a single random item based on the configured weights.

Returns

TypeDescription
ComparableA randomly selected item from the list.

GetWithSeed()

@classmethod
def GetWithSeed(
seed: rand.Source
) - > (Comparable, error)

Retrieves a randomly selected item from the list using a provided random number generator seed. Callers use this to ensure reproducible random selections.

Parameters

NameTypeDescription
seedrand.SourceThe random number generator source to use for selection, allowing for reproducible results.

Returns

TypeDescription
(Comparable, error)A randomly selected item from the list and an error if the selection fails.

List()

@classmethod
def List() - > []Comparable

Returns all items currently in the weighted random list. Callers use this to inspect the full set of items managed by the list.

Returns

TypeDescription
[]ComparableA slice containing all items in the weighted random list.

Len()

@classmethod
def Len() - > int

Returns the number of items currently in the weighted random list. Callers use this to determine the size of the list.

Returns

TypeDescription
intThe total count of items in the list.