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](comparable.md?sid=flytestdlib_random_comparable)
Retrieves a randomly selected item from the list, weighted by its assigned probability. Callers use this to obtain a single item based on the defined weight distribution.
Returns
| Type | Description |
|---|---|
[Comparable](comparable.md?sid=flytestdlib_random_comparable) | A randomly selected item from the list. |
GetWithSeed()
@classmethod
def GetWithSeed(
seed: rand.Source
) - > ([Comparable](comparable.md?sid=flytestdlib_random_comparable), error)
Retrieves a randomly selected item from the list using a provided random number generator seed. Callers use this to obtain a reproducible random item selection.
Parameters
| Name | Type | Description |
|---|---|---|
| seed | rand.Source | The random number generator source to use for selection, allowing for reproducible results. |
Returns
| Type | Description |
|---|---|
([Comparable](comparable.md?sid=flytestdlib_random_comparable), error) | A randomly selected item from the list and an error if the operation fails. |
List()
@classmethod
def List() - > [][Comparable](comparable.md?sid=flytestdlib_random_comparable)
Returns all items currently in the weighted random list. Callers use this to inspect the full collection of items managed by the list.
Returns
| Type | Description |
|---|---|
[][Comparable](comparable.md?sid=flytestdlib_random_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 weighted random list. |