prng

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2024 License: BSD-3-Clause Imports: 3 Imported by: 48

Documentation

Overview

Package prng provides random source PRNG implementations.

PRNG implementations provided in package prng may be used directly as rand.Source values for the golang.org/x/exp/rand package, and for the math rand package via a wrapper type.

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 implements the 32 bit Mersenne Twister PRNG. MT19937 is the default PRNG for a wide variety of programming systems. See https://en.wikipedia.org/wiki/Mersenne_Twister.

func NewMT19937

func NewMT19937() *MT19937

NewMT19937 returns a new MT19937 PRNG. The returned PRNG will use the default seed 5489 unless the Seed method is called with another value.

func (*MT19937) MarshalBinary

func (src *MT19937) MarshalBinary() ([]byte, error)

MarshalBinary returns the binary representation of the current state of the generator.

func (*MT19937) Seed

func (src *MT19937) Seed(seed uint64)

Seed uses the provided seed value to initialize the generator to a deterministic state. Only the lower 32 bits of seed are used to seed the PRNG.

func (*MT19937) SeedFromKeys

func (src *MT19937) SeedFromKeys(keys []uint32)

SeedFromKeys uses the provided seed key value to initialize the generator to a deterministic state. It is provided for compatibility with C implementations.

func (*MT19937) Uint32

func (src *MT19937) Uint32() uint32

Uint32 returns a pseudo-random 32-bit unsigned integer as a uint32.

func (*MT19937) Uint64

func (src *MT19937) Uint64() uint64

Uint64 returns a pseudo-random 64-bit unsigned integer as a uint64. It makes use of two calls to Uint32 placing the first result in the upper bits and the second result in the lower bits of the returned value.

func (*MT19937) UnmarshalBinary

func (src *MT19937) UnmarshalBinary(data []byte) error

UnmarshalBinary sets the state of the generator to the state represented in data.

type MT19937_64

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

MT19937_64 implements the 64 bit Mersenne Twister PRNG. MT19937_64 is the 64 bit version of MT19937, it has the same sized state, but generates a different sequence. See https://en.wikipedia.org/wiki/Mersenne_Twister.

func NewMT19937_64

func NewMT19937_64() *MT19937_64

NewMT19937_64 returns a new MT19937_64 PRNG. The returned PRNG will use the default seed 5489 unless the Seed method is called with another value.

func (*MT19937_64) MarshalBinary

func (src *MT19937_64) MarshalBinary() ([]byte, error)

MarshalBinary returns the binary representation of the current state of the generator.

func (*MT19937_64) Seed

func (src *MT19937_64) Seed(seed uint64)

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

func (*MT19937_64) SeedFromKeys

func (src *MT19937_64) SeedFromKeys(keys []uint64)

SeedFromKeys uses the provided seed key value to initialize the generator to a deterministic state. It is provided for compatibility with C implementations.

func (*MT19937_64) Uint64

func (src *MT19937_64) Uint64() uint64

Uint64 returns a pseudo-random 64-bit unsigned integer as a uint64.

func (*MT19937_64) UnmarshalBinary

func (src *MT19937_64) UnmarshalBinary(data []byte) error

UnmarshalBinary sets the state of the generator to the state represented in data.

type SplitMix64

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

SplitMix64 is the splitmix64 PRNG from http://prng.di.unimi.it/splitmix64.c. The zero value is usable directly. SplitMix64 is primarily provided to support seeding the xoshiro PRNGs.

func NewSplitMix64

func NewSplitMix64(seed uint64) *SplitMix64

NewSplitMix64 returns a new pseudo-random splitmix64 source seeded with the given value.

func (*SplitMix64) MarshalBinary

func (src *SplitMix64) MarshalBinary() ([]byte, error)

MarshalBinary returns the binary representation of the current state of the generator.

func (*SplitMix64) Seed

func (src *SplitMix64) Seed(seed uint64)

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

func (*SplitMix64) Uint64

func (src *SplitMix64) Uint64() uint64

Uint64 returns a pseudo-random 64-bit unsigned integer as a uint64.

func (*SplitMix64) UnmarshalBinary

func (src *SplitMix64) UnmarshalBinary(data []byte) error

UnmarshalBinary sets the state of the generator to the state represented in data.

type Xoshiro256plus

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

Xoshiro256plus is the xoshiro256+ 1.0 PRNG from http://prng.di.unimi.it/xoshiro256plus.c. The xoshiro PRNGs are described in http://vigna.di.unimi.it/ftp/papers/ScrambledLinear.pdf and http://prng.di.unimi.it/. A Xoshiro256plus value is only valid if returned by NewXoshiro256plus.

func NewXoshiro256plus

func NewXoshiro256plus(seed uint64) *Xoshiro256plus

NewXoshiro256plus returns a new pseudo-random xoshiro256+ source seeded with the given value.

func (*Xoshiro256plus) MarshalBinary

func (src *Xoshiro256plus) MarshalBinary() ([]byte, error)

MarshalBinary returns the binary representation of the current state of the generator.

func (*Xoshiro256plus) Seed

func (src *Xoshiro256plus) Seed(seed uint64)

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

func (*Xoshiro256plus) Uint64

func (src *Xoshiro256plus) Uint64() uint64

Uint64 returns a pseudo-random 64-bit unsigned integer as a uint64.

func (*Xoshiro256plus) UnmarshalBinary

func (src *Xoshiro256plus) UnmarshalBinary(data []byte) error

UnmarshalBinary sets the state of the generator to the state represented in data.

type Xoshiro256plusplus

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

Xoshiro256plusplus is the xoshiro256++ 1.0 PRNG from http://prng.di.unimi.it/xoshiro256plusplus.c. The xoshiro PRNGs are described in http://vigna.di.unimi.it/ftp/papers/ScrambledLinear.pdf and http://prng.di.unimi.it/. A Xoshiro256plusplus value is only valid if returned by NewXoshiro256plusplus.

func NewXoshiro256plusplus

func NewXoshiro256plusplus(seed uint64) *Xoshiro256plusplus

NewXoshiro256plusplus returns a new pseudo-random xoshiro256++ source seeded with the given value.

func (*Xoshiro256plusplus) MarshalBinary

func (src *Xoshiro256plusplus) MarshalBinary() ([]byte, error)

MarshalBinary returns the binary representation of the current state of the generator.

func (*Xoshiro256plusplus) Seed

func (src *Xoshiro256plusplus) Seed(seed uint64)

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

func (*Xoshiro256plusplus) Uint64

func (src *Xoshiro256plusplus) Uint64() uint64

Uint64 returns a pseudo-random 64-bit unsigned integer as a uint64.

func (*Xoshiro256plusplus) UnmarshalBinary

func (src *Xoshiro256plusplus) UnmarshalBinary(data []byte) error

UnmarshalBinary sets the state of the generator to the state represented in data.

type Xoshiro256starstar

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

Xoshiro256starstar is the xoshiro256** 1.0 PRNG from http://prng.di.unimi.it/xoshiro256starstar.c. The xoshiro PRNGs are described in http://vigna.di.unimi.it/ftp/papers/ScrambledLinear.pdf and http://prng.di.unimi.it/. A Xoshiro256starstar value is only valid if returned by NewXoshiro256starstar.

func NewXoshiro256starstar

func NewXoshiro256starstar(seed uint64) *Xoshiro256starstar

NewXoshiro256starstar returns a new pseudo-random xoshiro256** source seeded with the given value.

func (*Xoshiro256starstar) MarshalBinary

func (src *Xoshiro256starstar) MarshalBinary() ([]byte, error)

MarshalBinary returns the binary representation of the current state of the generator.

func (*Xoshiro256starstar) Seed

func (src *Xoshiro256starstar) Seed(seed uint64)

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

func (*Xoshiro256starstar) Uint64

func (src *Xoshiro256starstar) Uint64() uint64

Uint64 returns a pseudo-random 64-bit unsigned integer as a uint64.

func (*Xoshiro256starstar) UnmarshalBinary

func (src *Xoshiro256starstar) UnmarshalBinary(data []byte) error

UnmarshalBinary sets the state of the generator to the state represented in data.

Jump to

Keyboard shortcuts

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