mrand

package
v0.0.0-...-c20f884 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package mrand implements extensions and conveniences for using the default math/rand package.

Index

Constants

This section is empty.

Variables

View Source
var (
	ExpFloat64  = DefaultRand.ExpFloat64
	Float32     = DefaultRand.Float32
	Float64     = DefaultRand.Float64
	Int         = DefaultRand.Int
	Int31       = DefaultRand.Int31
	Int31n      = DefaultRand.Int31n
	Int63       = DefaultRand.Int63
	Int63n      = DefaultRand.Int63n
	Intn        = DefaultRand.Intn
	NormFloat64 = DefaultRand.NormFloat64
	Perm        = DefaultRand.Perm
	Read        = DefaultRand.Read
	Seed        = DefaultRand.Seed
	Shuffle     = DefaultRand.Shuffle
	Uint32      = DefaultRand.Uint32
	Uint64      = DefaultRand.Uint64

	// extended methods
	Bytes   = DefaultRand.Bytes
	Hex     = DefaultRand.Hex
	Element = DefaultRand.Element
)

Methods off DefaultRand exported to the top level of this package.

View Source
var DefaultRand = NewSyncRand(rand.NewSource(time.Now().UnixNano()))

DefaultRand is an instance off Rand whose methods are directly exported by this package for convenience.

Functions

This section is empty.

Types

type Rand

type Rand struct {
	*rand.Rand
}

Rand extends the default rand.Rand type with extra functionality.

func NewSyncRand

func NewSyncRand(src rand.Source) Rand

NewSyncRand initializes and returns a new Rand instance using the given Source. The returned Rand will be safe for concurrent use.

This will panic if the given Source doesn't implement rand.Source64.

func (Rand) Bytes

func (r Rand) Bytes(n int) []byte

Bytes returns n random bytes.

func (Rand) Element

func (r Rand) Element(slice interface{}, weight func(i int) uint64) interface{}

Element returns a random element from the given slice.

If a weighting function is given then that function is used to weight each element of the slice relative to the others, based on whatever metric and scale is desired. The weight function must be able to be called more than once on each element.

func (Rand) Hex

func (r Rand) Hex(n int) string

Hex returns a random hex string which is n characters long.

Jump to

Keyboard shortcuts

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