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
| Type | Description |
|---|---|
Comparable | A 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
| Name | Type | Description |
|---|---|---|
| seed | rand.Source | The random number generator source to use for selection, allowing for reproducible results. |
Returns
| Type | Description |
|---|---|
(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
| Type | Description |
|---|---|
[]Comparable | A 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
| Type | Description |
|---|---|
int | The total count of items in the list. |