random

package
v0.53.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2024 License: GPL-3.0 Imports: 6 Imported by: 0

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.

func Uint64 added in v0.53.0

func Uint64() uint64

Uint64 returns a random uint64. This is a reimplementation of math/rand/v2.Uint64 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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL