Documentation
¶
Index ¶
- func Float() mat64.Float
- func GetUniqueRandomIndices(n int, indices []int, valid func(r int) bool) []int
- func GetUniqueRandomInt(n, max int, valid func(r int) bool) []int
- func ShuffleInPlace(xs []int, generator *LockedRand) []int
- func WeightedChoice(dist []float64) int
- type LockedRand
- func (lr *LockedRand) Float() (n float64)
- func (lr *LockedRand) Float32() (n float32)
- func (lr *LockedRand) Float64() (n float64)
- func (lr *LockedRand) Int() (n int)
- func (lr *LockedRand) Int31() (n int32)
- func (lr *LockedRand) Int31n(n int32) (r int32)
- func (lr *LockedRand) Int63() (n int64)
- func (lr *LockedRand) Int63n(n int64) (r int64)
- func (lr *LockedRand) Intn(n int) (r int)
- func (lr *LockedRand) NormFloat64() (n float64)
- func (lr *LockedRand) Perm(n int) (r []int)
- func (lr *LockedRand) Read(p []byte) (n int, err error)
- func (lr *LockedRand) Seed(seed uint64)
- func (lr *LockedRand) Shuffle(i int, swap func(i int, j int))
- func (lr *LockedRand) TwoInt63() (n1, n2 int64)
- func (lr *LockedRand) Uint32() (n uint32)
- func (lr *LockedRand) Uint64() (n uint64)
- func (lr *LockedRand) Uint64n(n uint64) uint64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Float ¶
Float returns, as a mat64.Float, a pseudo-random number in [0.0,1.0) from the default Source.
func GetUniqueRandomIndices ¶
GetUniqueRandomIndices select n mutually exclusive indices, using the global random. The callback checks whether an extracted index can be accepted, or not.
func GetUniqueRandomInt ¶
GetUniqueRandomInt generates n mutually exclusive integers up to max, using the default random source. The callback checks whether a generated number can be accepted, or not.
func ShuffleInPlace ¶
func ShuffleInPlace(xs []int, generator *LockedRand) []int
ShuffleInPlace pseudo-randomizes the order of elements, modifying the given slice in-place.
func WeightedChoice ¶
WeightedChoice performs a random generation of the indices based of the probability distribution itself. Please note that it uses the global random.
Types ¶
type LockedRand ¶
type LockedRand struct {
// contains filtered or unexported fields
}
LockedRand is an implementation of rand.Rand that is concurrency-safe. It is just a wrap of the standard rand.Rand with its operations protected by a sync.Mutex.
func NewLockedRand ¶
func NewLockedRand(seed uint64) *LockedRand
NewLockedRand creates a new LockedRand that implements all Rand functions that is safe for concurrent use.
func (*LockedRand) Float32 ¶
func (lr *LockedRand) Float32() (n float32)
Float32 returns, as a float32, a pseudo-random number in [0.0,1.0).
func (*LockedRand) Float64 ¶
func (lr *LockedRand) Float64() (n float64)
Float64 returns, as a float64, a pseudo-random number in [0.0,1.0).
func (*LockedRand) Int ¶
func (lr *LockedRand) Int() (n int)
Int returns a non-negative pseudo-random int.
func (*LockedRand) Int31 ¶
func (lr *LockedRand) Int31() (n int32)
Int31 returns a non-negative pseudo-random 31-bit integer as an int32.
func (*LockedRand) Int31n ¶
func (lr *LockedRand) Int31n(n int32) (r int32)
Int31n returns, as an int32, a non-negative pseudo-random number in [0,n). It panics if n <= 0.
func (*LockedRand) Int63 ¶
func (lr *LockedRand) Int63() (n int64)
Int63 returns a non-negative pseudo-random 63-bit integer as an int64.
func (*LockedRand) Int63n ¶
func (lr *LockedRand) Int63n(n int64) (r int64)
Int63n returns, as an int64, a non-negative pseudo-random number in [0,n). It panics if n <= 0.
func (*LockedRand) Intn ¶
func (lr *LockedRand) Intn(n int) (r int)
Intn returns, as an int, a non-negative pseudo-random number in [0,n). It panics if n <= 0.
func (*LockedRand) NormFloat64 ¶
func (lr *LockedRand) NormFloat64() (n float64)
NormFloat64 returns a normally distributed float64 in the range [-math.MaxFloat64, +math.MaxFloat64] with standard normal distribution (mean = 0, stddev = 1).
func (*LockedRand) Perm ¶
func (lr *LockedRand) Perm(n int) (r []int)
Perm returns, as a slice of n ints, a pseudo-random permutation of the integers [0,n).
func (*LockedRand) Read ¶
func (lr *LockedRand) Read(p []byte) (n int, err error)
Read generates len(p) random bytes and writes them into p. It always returns len(p) and a nil error. Read should not be called concurrently with any other Rand method.
func (*LockedRand) Seed ¶
func (lr *LockedRand) Seed(seed uint64)
Seed uses the provided seed value to initialize the generator to a deterministic state. Seed should not be called concurrently with any other Rand method.
func (*LockedRand) Shuffle ¶
func (lr *LockedRand) Shuffle(i int, swap func(i int, j int))
Shuffle pseudo-randomizes the order of elements using the default Source. n is the number of elements. Shuffle panics if n < 0. swap swaps the elements with indexes i and j.
func (*LockedRand) TwoInt63 ¶
func (lr *LockedRand) TwoInt63() (n1, n2 int64)
TwoInt63 generates 2 random int64 without locking twice.
func (*LockedRand) Uint32 ¶
func (lr *LockedRand) Uint32() (n uint32)
Uint32 returns a pseudo-random 32-bit value as a uint32.
func (*LockedRand) Uint64 ¶
func (lr *LockedRand) Uint64() (n uint64)
Uint64 returns a pseudo-random 64-bit value as a uint64.
func (*LockedRand) Uint64n ¶
func (lr *LockedRand) Uint64n(n uint64) uint64
Uint64n returns, as a uint64, a pseudo-random number in [0,n). It is guaranteed more uniform than taking a Source value mod n for any n that is not a power of 2.