Documentation
¶
Index ¶
- Constants
- func Float64() float64
- func Float64Bisect(round bool) float64
- func Float64_64() float64
- func Float64_117() float64
- func Float64full() float64
- func Int() int
- func Int63() int64
- func Int63n(n int64) int64
- func Intn(n int) int
- func NewSource(seed int64) uint64
- func OverlapProbability(n, L, P float64) (lower, upper float64)
- func RandomReal() float64
- func ResetGlobalOutlet(seed uint64)
- func Seed(seed uint64)
- func Splitmix(seed *uint64) uint64
- func SplitmixJump(seed *uint64, jump int64)
- func Uint64() uint64
- func Uint64n(n uint64) uint64
- type MCG
- type Outlet
- type Prng
- func (r *Prng) Float64() float64
- func (r *Prng) Float64Bisect(round bool) float64
- func (r *Prng) Float64_64() float64
- func (r *Prng) Float64_117() float64
- func (r *Prng) Float64full() float64
- func (r *Prng) Int() int
- func (r *Prng) Int63() int64
- func (r *Prng) Int63n(n int64) int64
- func (r *Prng) Intn(n int) int
- func (r *Prng) Jump()
- func (r *Prng) RandomReal() float64
- func (r *Prng) ReadState(b []byte)
- func (r *Prng) Seed(seed uint64)
- func (r *Prng) State() []byte
- func (r *Prng) Uint64() uint64
- func (r *Prng) Uint64n(n uint64) uint64
- func (r *Prng) WriteState(b []byte)
- type Xoro
- func (x *Xoro) Float64() float64
- func (x *Xoro) Float64Bisect(round bool) float64
- func (x *Xoro) Float64_64() float64
- func (x *Xoro) Float64_64R() float64
- func (x *Xoro) Float64_117() float64
- func (x *Xoro) Float64_117R() float64
- func (x *Xoro) Float64_128() float64
- func (x *Xoro) Float64full() float64
- func (x *Xoro) Float64fullR() float64
- func (x *Xoro) Jump()
- func (x *Xoro) JumpLong()
- func (x *Xoro) JumpShort()
- func (x Xoro) NextState() Xoro
- func (x *Xoro) RandomReal() float64
- func (x *Xoro) ReadState(b []byte)
- func (x *Xoro) Seed(seed uint64)
- func (x *Xoro) State() []byte
- func (x *Xoro) Uint64() (next uint64)
- func (x *Xoro) WriteState(b []byte)
- func (x *Xoro) Xoroshiro128plus() (next uint64)
- type Xosh
- func (x *Xosh) Float64() float64
- func (x *Xosh) Float64_64() float64
- func (x *Xosh) Float64_117() float64
- func (x *Xosh) Float64full() float64
- func (x *Xosh) Jump()
- func (x *Xosh) JumpLong()
- func (x Xosh) NextState() Xosh
- func (x *Xosh) ReadState(b []byte)
- func (x *Xosh) Seed(seed uint64)
- func (x *Xosh) State() []byte
- func (x *Xosh) Uint64() (next uint64)
- func (x *Xosh) WriteState(b []byte)
- func (x *Xosh) Xoshiro256plus() (next uint64)
- func (x *Xosh) Xoshiro256plusplus() (next uint64)
Constants ¶
const ( PrngStateSize = 16 XoroStateSize = 16 XoshStateSize = 32 )
Random state sizes in bytes.
Variables ¶
This section is empty.
Functions ¶
func Float64 ¶
func Float64() float64
Float64 returns a uniformly distributed pseudo-random float64 from [0, 1). The distribution is 2^53 evenly spaced floats with spacing 2^-53.
func Float64Bisect ¶
Float64Bisect returns a uniformly distributed pseudo-random float64 from [0, 1). The distribution includes all floats. Float64Bisect is a slow function only for validating other functions distributions. if round is true, rounding is used.
func Float64_64 ¶
func Float64_64() float64
Float64_64 returns a uniformly distributed pseudo-random float64 from [0, 1). The distribution includes all floats in [2^-12, 1) and 2^52 evenly spaced floats in [0, 2^-12) with spacing 2^-64.
func Float64_117 ¶
func Float64_117() float64
Float64_117 returns a uniformly distributed pseudo-random float64 from [0, 1). The distribution includes all floats in [2^-65, 1) and 2^52 evenly spaced floats in [0, 2^-65) with spacing 2^-117.
func Float64full ¶
func Float64full() float64
Float64full returns a uniformly distributed pseudo-random float64 from [0, 1). The distribution includes all floats in [2^-1023, 1) and 0.
func OverlapProbability ¶
OverlapProbability function calculates lower and upper bound of the probability for an event that at least two random streams overlap when splitting a single prng by random seeding. Formulas from http://vigna.di.unimi.it/ftp/papers/overlap.pdf. n = number of splitted parallel prng's L = lenght of the random stream for each prng P = full period of the prng. Normal float64 arithmetic used doesn't give enough lower lim accuracy for long full periods.
func RandomReal ¶
func RandomReal() float64
RandomReal returns a uniformly distributed pseudo-random float64 from [0, 1). The distribution includes all floats in [2^-1023, 1) and 0.
func ResetGlobalOutlet ¶
func ResetGlobalOutlet(seed uint64)
ResetGlobalOutlet resets the globalOutlet by the seed. This can be made only once.
func Splitmix ¶
Splitmix is a 64-bit state SplitMix64 pseudo-random number generator from http://prng.di.unimi.it/splitmix64.c . The pointer parameter seed is used as the random state. Splitmix is used here to blend seeds for the other generators. It is a good and quite fast 64-bit state generator for other uses too.
func SplitmixJump ¶
SplitmixJump (&seed, jump) sets the seed to the same value as jump calls to Splitmix(&seed). Jump can be negative.
Types ¶
type MCG ¶
type MCG struct {
// contains filtered or unexported fields
}
A MCG implements 64-bit multiplicative congruential pseudorandom number generator (MCG) modulo 2^64 with 64-bit state and maximun period of 2^62.
func (*MCG) Float64 ¶
Float64 returns a uniformly distributed pseudo-random float64 from [0, 1). The distribution is 2^53 evenly spaced floats with spacing 2^-53. Float64 uses multiplicative congruential pseudorandom number generator (MCG) mod 2^64. 53 high bits of the MCG are considered good enough for a fast float64, but they don't pass random tests for the last ~3 bits.
func (*MCG) Float64_64 ¶
Float64_64 returns a uniformly distributed pseudo-random float64 from [0, 1). The distribution includes all floats in [2^-12, 1) and 2^52 evenly spaced floats in [0, 2^-12) with spacing 2^-64. This function inlines ok.
type Outlet ¶
type Outlet struct {
// contains filtered or unexported fields
}
Outlet is a delivery type of pseudo-random number generators with non-overlapping random streams. Methods of Outlet use sync.Mutex to protect the Outlet for simultaneous access.
func (*Outlet) Next ¶
Next returns the next rng from Outlet. Each rng has 2^64 long random stream, which is not overlapping with other Rands streams. Next is safe for concurrent use by multiple goroutines.
type Prng ¶
type Prng struct {
// contains filtered or unexported fields
}
A Prng is a wrapper around the actual pseudo-random number generator. It is now fixed to xoroshiro128 generator instead of having more flexible rng interface. This way we get faster inlineable functions, but cannot change the rng in an application.
func NewPrngSlice ¶
NewPrngSlice returns a slice of n Rands with non-overlapping random streams. The first Prng is seeded by seed.
func Next ¶
func Next() Prng
Next returns the next non-overlapping stream Prng from globalOutlet. Next is safe for concurrent use by multiple goroutines.
func (*Prng) Float64 ¶
Float64 returns a uniformly distributed pseudo-random float64 from [0, 1). The distribution includes 2^53 evenly spaced floats with spacing 2^-53.
func (*Prng) Float64Bisect ¶
Float64Bisect returns a uniformly distributed pseudo-random float64 from [0, 1). The distribution includes all floats. Float64Bisect is a slow function only for validating other functions distributions.
func (*Prng) Float64_64 ¶
Float64_64 returns a uniformly distributed pseudo-random float64 from [0, 1). The distribution includes all floats in [2^-12, 1) and 2^52 evenly spaced floats in [0, 2^-12) with spacing 2^-64.
func (*Prng) Float64_117 ¶
Float64_117 returns a uniformly distributed pseudo-random float64 from [0, 1). The distribution includes all floats in [2^-65, 1) and 2^52 evenly spaced floats in [0, 2^-65) with spacing 2^-117.
func (*Prng) Float64full ¶
Float64full returns a uniformly distributed pseudo-random float64 from [0, 1). The distribution includes all floats in [0, 1).
func (*Prng) Jump ¶
func (r *Prng) Jump()
Jump sets r to the same state as 2^64 calls to r.Uint64. Jump can be used to generate 2^64 non-overlapping subsequences for parallel computation.
func (*Prng) RandomReal ¶
RandomReal returns a uniformly distributed pseudo-random float64 from [0, 1]. The distribution includes all floats in [0, 1]. http://prng.di.unimi.it/random_real.c
func (*Prng) ReadState ¶
ReadState reads the state of the generator r from b []byte. r.ReadState(r.State()) changes nothing.
func (*Prng) Seed ¶
Seed seeds a Prng by the seed. Any seed is ok. Do not seed Rands created by Next or NewPrngSlice.
func (*Prng) Uint64n ¶
Uint64n returns a pseudo-random number in [0,n) as an uint64. Uint64n doesn't make any bias correction. The bias with 64-bit numbers is very small and propably not detectable from the random stream.
func (*Prng) WriteState ¶
WriteState writes the state of the generator r to b []byte.
type Xoro ¶
type Xoro struct {
// contains filtered or unexported fields
}
A Xoro with a xoroshiro prng implements a 64-bit generator with 128-bit state. A Xoro is the den of the xoroshiros holding their two 64-bit eggs.
func NewXoro ¶
NewXoro returns a new xoroshiro128 generator seeded by the seed. Float64 uses xoroshiro128+ and Uint64 xoroshiro128**. Both xoroshiros update a Xoro in the same way (same linear engine) and we can use a single Xoro for both functions without interfering random stream properties.
func NewXoroSlice ¶
NewXoroSlice returns a slice of n xoroshiro128 generators with non-overlapping 2^64 long random streams. First generator is seeded by seed.
func NextXoro ¶
func NextXoro() Xoro
NextXoro returns the next non-overlapping stream xoroshiro128 from globalOutlet. This generator has only Float64 and Uint64 prn methods.
func (*Xoro) Float64 ¶
Float64 returns a uniformly distributed pseudo-random float64 from [0, 1). The distribution is 2^53 evenly spaced floats with spacing 2^-53.
func (*Xoro) Float64Bisect ¶
Float64Bisect returns a uniformly distributed pseudo-random float64 value in [0, 1). If round is true, rounding is applied and the range is [0, 1]. All floats, normal and subnormal, are included.
func (*Xoro) Float64_64 ¶
Float64_64 returns a uniformly distributed pseudo-random float64 from [0, 1). The distribution includes all floats in [2^-12, 1) and 2^52 evenly spaced floats in [0, 2^-12) with spacing 2^-64.
func (*Xoro) Float64_64R ¶
Float64_64R returns a uniformly distributed pseudo-random float64 from [0, 1] using rounding. The distribution includes all rounded floats in [2^-11, 1] and 2^53 evenly spaced floats in [0, 2^-11) with spacing 2^-64.
func (*Xoro) Float64_117 ¶
Float64_117 returns a uniformly distributed pseudo-random float64 from [0, 1). The distribution includes all floats in [2^-65, 1) and 2^52 evenly spaced floats in [0, 2^-65) with spacing 2^-117.
func (*Xoro) Float64_117R ¶
Float64_117R returns a uniformly distributed pseudo-random float64 from [0, 1] using rounding. The distribution includes all floats in [2^-65, 1] and 2^52 evenly spaced floats in [0, 2^-65) with spacing 2^-117.
func (*Xoro) Float64full ¶
Float64full returns a uniformly distributed pseudo-random float64 from [0, 1). The distribution includes all floats in [0, 1). Float64full is equivalent to Float64Bisect in truncate mode.
func (*Xoro) Float64fullR ¶
Float64fullR returns a uniformly distributed pseudo-random float64 from [0, 1] using rounding. The distribution includes all floats in [0, 1]. Float64fullR is equivalent to Float64Bisect in rounding mode.
func (*Xoro) Jump ¶
func (x *Xoro) Jump()
Jump sets x to the same state as 2^64 calls to x.Uint64 or 2^32 calls to x.JumpShort.
func (*Xoro) JumpLong ¶
func (x *Xoro) JumpLong()
JumpLong sets x to the same state as 2^96 calls to x.Uint64 or 2^32 calls to x.Jump.
func (*Xoro) JumpShort ¶
func (x *Xoro) JumpShort()
JumpShort sets x to the same state as 2^32 calls to x.Uint64.
func (Xoro) NextState ¶
NextState returns the next Xoro state of the xoroshiro128+/** linear engine.
func (*Xoro) RandomReal ¶
RandomReal returns a uniformly distributed pseudo-random float64 from [0, 1]. The distribution includes all floats, but may miss very few subnormal floats in in [0, 2^-1022). http://prng.di.unimi.it/random_real.c RandomReal is equivalent to Float64Bisect in rounding mode in [2^-1024, 1].
func (*Xoro) WriteState ¶
WriteState writes the current state of the generator x to b. WriteState without allocation is faster than State().
func (*Xoro) Xoroshiro128plus ¶
Xoroshiro128plus is xoroshiro128+
type Xosh ¶
type Xosh struct {
// contains filtered or unexported fields
}
A Xosh with a xoshiro256 prng implements a 64-bit generator with 256-bit state.
func NewXoshSlice ¶
NewXoshSlice returns a slice of n xoshiro256 generators with non-overlapping 2^128 long random streams. First generator is seeded by the seed.
func NextXosh ¶
func NextXosh() Xosh
NextXosh returns the next non-overlapping stream xoshiro256 from globalOutlet. This generator has only Float64 and Uint64 prn methods.
func (*Xosh) Float64 ¶
Float64 returns a uniformly distributed pseudo-random float64 from [0, 1). The distribution includes 2^53 evenly spaced floats with spacing 2^-53.
func (*Xosh) Float64_64 ¶
Float64_64 returns a uniformly distributed pseudo-random float64 from [0, 1). The distribution includes all floats in [2^-12, 1) and 2^52 evenly spaced floats in [0, 2^-12) with spacing 2^-64.
func (*Xosh) Float64_117 ¶
Float64_117 returns a uniformly distributed pseudo-random float64 from [0, 1). The distribution includes all floats in [2^-65, 1) and 2^52 evenly spaced floats in [0, 2^-65) with spacing 2^-117.
func (*Xosh) Float64full ¶
Float64full returns a uniformly distributed pseudo-random float64 from [0, 1). The distribution includes all floats in [0, 1). Float64full is equivalent to Float64Bisect in truncate mode.
func (*Xosh) JumpLong ¶
func (x *Xosh) JumpLong()
JumpLong sets x to the same state as 2^192 calls to x.Uint64 or 2^64 calls to x.Jump.
func (*Xosh) WriteState ¶
WriteState writes the current state of the generator x to b. WriteState without allocations is faster than State().
func (*Xosh) Xoshiro256plus ¶
Xoshiro256plus is xoshiro256+
func (*Xosh) Xoshiro256plusplus ¶
Xoshiro256plusplus is xoshiro256++