Documentation ¶
Overview ¶
Package xoshiro provides an implementation for a pseudo-random number generator (PRNG) using the xoshiro256** and xoshiro256+ algorithms.
Period: 2^256-1. State size: 256 bits.
Go implementation based on a C reference implementation by David Blackman and Sebastiano Vigna. For further information: http://xoshiro.di.unimi.it/
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Rng256P ¶
type Rng256P [4]uint64
Rng256P encapsulates a xoshiro256+ PRNG.
xoshiro256+ 1.0 is Blackman & Vigna's best and fastest generator for floating-point numbers. The authors suggest to use its upper bits for floating-point generation, as it is slightly faster than xoshiro256**. It passes all tests the authors are aware of except for the lowest three bits, which might fail linearity tests (and just those), so if low linear complexity is not considered an issue (as it is usually the case) it can be used to generate 64-bit outputs, too.
The authors suggest to use a sign test to extract a random Boolean value, and right shifts to extract subsets of bits.
Note that the Go implementation of Rand.Float64 uses the upper bits as suggested.
Example ¶
package main import ( "fmt" "math/rand" "github.com/db47h/rand64/v3/xoshiro" ) const SEED1 = 1387366483214 func main() { src := xoshiro.Rng256P{} src.Seed(SEED1) rng := rand.New(&src) for i := 0; i < 4; i++ { fmt.Printf(" %d", rng.Uint32()) } fmt.Println("") for i := 0; i < 4; i++ { fmt.Printf(" %d", rng.Uint64()) } fmt.Println("") // Play craps for i := 0; i < 10; i++ { fmt.Printf(" %d%d", rng.Intn(6)+1, rng.Intn(6)+1) } }
Output: 2171228231 173189436 470990771 2412873522 1816180620218953111 7257068590675658289 8111314002208617320 6106779797696663770 46 33 61 55 34 41 65 44 22 33
type Rng256SS ¶
type Rng256SS [4]uint64
Rng256SS encapsulates a xoshiro256** PRNG.
xoshiro256** 1.0 is Black,an & Vigna's all-purpose, rock-solid generator. It has excellent (sub-ns) speed, a state (256 bits) that is large enough for any parallel application, and it passes all tests the authors are aware of.
For generating just floating-point numbers, xoshiro256+ is even faster.
Example ¶
package main import ( "fmt" "math/rand" "github.com/db47h/rand64/v3/xoshiro" ) const SEED1 = 1387366483214 func main() { src := xoshiro.Rng256SS{} src.Seed(SEED1) rng := rand.New(&src) for i := 0; i < 4; i++ { fmt.Printf(" %d", rng.Uint32()) } fmt.Println("") for i := 0; i < 4; i++ { fmt.Printf(" %d", rng.Uint64()) } fmt.Println("") // Play craps for i := 0; i < 10; i++ { fmt.Printf(" %d%d", rng.Intn(6)+1, rng.Intn(6)+1) } }
Output: 1703513406 2124925634 3601057375 1523263934 14206081294295289219 1400819388980187612 655760235528857176 11230280953057933127 11 13 64 51 53 15 16 55 12 61