randutil

package module
v3.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2020 License: MIT Imports: 5 Imported by: 0

README

[DEPRECATED] Use golang.org/x/exp/rand#PCGSource and gonum.org/v1/gonum/stat/distuv instead.

randutil GoDoc

This is a Go package for providing some utilities for random.

This Package randutil provides a utility function to get non-negative pesudo-random int using math/rand or crypto/rand.

This package also provides Chooser which chooses an item from choices. Each choice has a weight which affects possibility for it to be choosed.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MultiIntnNoDup added in v3.0.1

func MultiIntnNoDup(src rand.Source, m, n int) []int

MultiIntnNoDup returns m multiple random integers of range [0, n) without duplication.

func NewSeed

func NewSeed() uint64

NewSeed creats a new random seed.

Types

type Uniform

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

Uniform is a uniform random chooser.

func NewUniform

func NewUniform(src rand.Source) *Uniform

NewUniform creates a Uniform instance.

func (*Uniform) Choose

func (u *Uniform) Choose(values []string) string

Choose chooses one value from values randomly.

type Weighted

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

Weighted is a weighted random chooser.

func NewWeighted

func NewWeighted(src rand.Source, weights []float64) *Weighted

NewWeighted creates a weighted random chooser. If src is nil, the rand.Float will be used.

func (*Weighted) Choose

func (w *Weighted) Choose(values []string) string

Choose chooses one value from values.

Jump to

Keyboard shortcuts

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