Documentation ¶
Overview ¶
Package mrand implements extensions and conveniences for using the default math/rand package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
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.
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 ¶
Rand extends the default rand.Rand type with extra functionality.
func NewSyncRand ¶
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) Element ¶
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.