Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Int64N ¶ added in v0.53.0
func Int64N[T constraints.Integer](max T) int64
Int64N returns a random int64 between 0 and max. This is a reimplementation of math/rand/v2.Int64N using a cryptographically secure random number generator.
Types ¶
type WeightedChooser ¶
type WeightedChooser[T any] struct { // contains filtered or unexported fields }
WeightedChooser allows to randomly choose an entry based on their weights (higher weight = higher chance of being chosen). Based on the subtraction method described in https://eli.thegreenplace.net/2010/01/22/weighted-random-generation-in-python/
func NewWeightedChooser ¶ added in v0.53.0
func NewWeightedChooser[T any]() *WeightedChooser[T]
func (*WeightedChooser[T]) Add ¶
func (w *WeightedChooser[T]) Add(value T, weight int)
func (*WeightedChooser[T]) Pick ¶ added in v0.53.0
func (w *WeightedChooser[T]) Pick() (T, error)
Pick choose a random entry based on their weights, and removes it from the list
func (*WeightedChooser[T]) Remove ¶
func (w *WeightedChooser[T]) Remove(i int) error
func (*WeightedChooser[T]) Size ¶
func (w *WeightedChooser[T]) Size() int
Click to show internal directories.
Click to hide internal directories.