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. Entries with zero weight will be ignored unless all entries have zero weight, in which case they will be assigned equal weights. |
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. |