bandrng

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2020 License: GPL-3.0 Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 determinisic 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