mt19937

package
v1.0.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2024 License: BlueOak-1.0.0 Imports: 1 Imported by: 0

Documentation

Overview

Package mt19937 implements the 64-bit version of the Mersenne Twister (MT) pseudo-random number generator (PRNG) with a period of 2^19937-1, also known as mt19937_64, according to the reference implementation by Matsumoto and Nishimura at http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt64.html

MT is not cryptographically secure. Given a sufficiently long sequence of the generated values, one may predict additional values without knowing the seed. A secure hashing algorithm should be used with MT if a CSPRNG is required.

When possible, the MT generator should be seeded with a slice of bytes or uint64 values to address known "zero-excess" seed initialization issues where "shifted" sequences may be generated for seeds with only a few non-zero bits. For more information, see http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/emt19937ar.html

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Source

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

Source is a pseudo-random number generator that satisfies both math/rand.Source and math/rand.Source64.

func NewSource

func NewSource() *Source

NewSource creates a new unseeded Source.

func (*Source) Int63

func (s *Source) Int63() int64

Int63 returns the next pseudo-random integer on [0, 2^63-1) in the sequence. Both Uint64 and Int63 advance the sequence. Int63 satisfies math/rand.Source64.

func (*Source) Seed

func (s *Source) Seed(seed int64)

Seed initializes the source with the provided value. Note that SeedBytes or SeedValues should be preferred since Mersenne Twister suffers from a "zero-excess" initial state defect where seeds with many zero bits can result in similar/"shifted" sequences. The authors describe the issues: http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/emt19937ar.html

func (*Source) SeedBytes

func (s *Source) SeedBytes(b []byte)

SeedBytes seeds the mt19937 engine with up to 2496 bytes from a slice. Only the first 2496 bytes of the slice are used. Additional elements are unused.

func (*Source) SeedVals

func (s *Source) SeedVals(v []uint64)

SeedVals seeds the mt19937 engine with up to 312 uint64 values. Only the first 312 values of the slice are used. Additional elements are unused.

func (*Source) Uint64

func (s *Source) Uint64() uint64

Uint64 returns the next pseudo-random integer on [0, 2^64-1) in the sequence. Uint64 satisfies math/rand.Source.

Jump to

Keyboard shortcuts

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