xoshiro

package
v3.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2019 License: ISC Imports: 2 Imported by: 0

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

func (*Rng256P) Int63

func (rng *Rng256P) Int63() int64

Int63 returns a non-negative pseudo-random 63-bit integer as an int64.

func (*Rng256P) Seed

func (rng *Rng256P) Seed(seed int64)

Seed uses the provided seed value to initialize the generator to a deterministic state.

func (*Rng256P) Uint64

func (rng *Rng256P) Uint64() uint64

Uint64 returns a pseudo-random 64-bit value as a uint64.

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

func (*Rng256SS) Int63

func (rng *Rng256SS) Int63() int64

Int63 returns a non-negative pseudo-random 63-bit integer as an int64.

func (*Rng256SS) Seed

func (rng *Rng256SS) Seed(seed int64)

Seed uses the provided seed value to initialize the generator to a deterministic state.

func (*Rng256SS) Uint64

func (rng *Rng256SS) Uint64() uint64

Uint64 returns a pseudo-random 64-bit value as a uint64.

Jump to

Keyboard shortcuts

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