mt19937

package
v0.1.1 Latest Latest
Warning

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

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

Documentation

Overview

Package mt19937 implements a Mersenne Twister source of random numbers satisfying the rand.Source64 interface.

Structs in mt19937 package are not safe for concurrent access by different goroutines. If more than one goroutine accesses the PRNG, the callers must synchronise access using sync.Mutex or similar.

For random numbers suitable for security-sensitive work, see the crypto/rand package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MT19937

type MT19937 struct {
	// contains filtered or unexported fields
}

MT19937 holds the state of one instance of the Mersenne Twister PRNG. New instances can be allocated using the mt19937.New() function. MT19937 implements the rand.Source64 interface and rand.New() from the math/rand package can be used to generate different distributions from a MT19937 PRNG.

This struct is not safe for concurrent access by different goroutines. If more than one goroutine accesses the PRNG, the callers must synchronise access using sync.Mutex or similar.

func New

func New(seed int64) *MT19937

New returns a new instance of the 64bit Mersenne Twister with the specified seed.

func (*MT19937) Int63

func (mt *MT19937) Int63() int64

Int63 generates a (pseudo-)random 63bit value. The output can be used as a replacement for a sequence of independent, uniformly distributed samples in the range 0, 1, ..., 2^63-1. This method is part of the rand.Source interface.

func (*MT19937) Read

func (mt *MT19937) Read(p []byte) (n int, err error)

Read fills `p` with (pseudo-)random bytes. This method implements the io.Reader interface. The returned length `n` always equals `len(p)` and `err` is always nil.

func (*MT19937) Seed

func (mt *MT19937) Seed(seed int64)

Seed uses the given 64bit value to initialise the generator state. This method is part of the rand.Source interface.

func (*MT19937) SeedFromSlice

func (mt *MT19937) SeedFromSlice(key []uint64)

SeedFromSlice uses the given slice of 64bit values to set the generator state.

func (*MT19937) Uint64

func (mt *MT19937) Uint64() uint64

Uint64 generates a (pseudo-)random 64bit value. The output can be used as a replacement for a sequence of independent, uniformly distributed samples in the range 0, 1, ..., 2^64-1.

Jump to

Keyboard shortcuts

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