bandrng

package
v2.5.4 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2023 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChooseOne

func ChooseOne(rng *Rng, weights []uint64) int

ChooseOne randomly picks an index between 0 and len(weights)-1 inclusively. Each index has the probability of getting selected based on its weight.

func ChooseSome

func ChooseSome(rng *Rng, weights []uint64, cnt int) []int

ChooseSome randomly picks non-duplicate "cnt" indexes between 0 and len(weights)-1 inclusively. The function calls ChooseOne to get an index based on the given weights. When an index is chosen, it gets removed from the pool. The process gets repeated until "cnt" indexes are chosen.

func ChooseSomeMaxWeight

func ChooseSomeMaxWeight(rng *Rng, weights []uint64, cnt int, tries int) []int

ChooseSomeMaxWeight performs ChooseSome "tries" times and returns the sampling with the highest weight sum among all tries.

Types

type Rng

type Rng struct {
	// contains filtered or unexported fields
}

Rng implements a simple deterministic random number generator. Starting from an initial entropy, nonce, and personalizationString, it utilizes HMAC_DRBG construct as per NIST Special Publication 800-90A to produce a stream of random uint64 integers.

func NewRng

func NewRng(entropyInput, nonce, personalizationString []byte) (*Rng, error)

NewRng creates a new psudo-random generator, using the given seeds as the initial random source.

func (*Rng) NextUint64

func (r *Rng) NextUint64() uint64

NextUint64 returns the next 64-bit unsigned random integer produced by this generator.

Jump to

Keyboard shortcuts

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