NewWeightedRandom
Given a list of entries with weights, returns WeightedRandomList
def NewWeightedRandom(
ctx: context.Context,
entries: []Entry
) - > WeightedRandomList, error
Given a list of entries with weights, returns WeightedRandomList
Parameters
| Name | Type | Description |
|---|---|---|
| ctx | context.Context | The context for the operation, used for logging and cancellation. |
| entries | []Entry | A slice of Entry objects, each containing an item and its associated weight. These entries will be used to construct the weighted random list. |
Returns
| Type | Description |
|---|---|
WeightedRandomList, error | A WeightedRandomList object that can be used to select entries based on their assigned weights, or an error if validation fails. |