Skip to main content

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​

NameTypeDescription
ctxcontext.ContextThe context for the operation, used for logging and cancellation.
entries[]EntryA slice of Entry objects, each containing an item and its associated weight. These entries will be used to construct the weighted random list.

Returns​

TypeDescription
WeightedRandomList, errorA WeightedRandomList object that can be used to select entries based on their assigned weights, or an error if validation fails.