Package Usage: go: github.com/mroth/weightedrand/v2
Package weightedrand contains a performant data structure and algorithm used
to randomly select an element from some kind of list, where the chances of
each element to be selected not being equal, but defined by relative
"weights" (or probabilities). This is called weighted random selection.
This package creates a presorted cache optimized for binary search, allowing
for repeated selections from the same set to be significantly faster,
especially for large data sets.
In this example, we create a Chooser to pick from amongst various emoji fruit
runes. We assign a numeric weight to each choice. These weights are relative,
not on any absolute scoring system. In this trivial case, we will assign a
weight of 0 to all but one fruit, so that the output will be predictable.
4 versions
Latest release: almost 2 years ago
43 dependent packages
View more package details: https://packages.ecosystem.code.gouv.fr/registries/proxy.golang.org/packages/github.com/mroth/weightedrand/v2