pcg64

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2025 License: Unlicense Imports: 5 Imported by: 0

Documentation

Overview

Package pcg64 implements the PCG-64 random number generator.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PCG64

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

PCG64 represents the state of a PCG-64 random number generator.

func New

func New() *PCG64

New creates a new PCG64 instance seeded with the current time.

func (*PCG64) Float32

func (p *PCG64) Float32() float32

Float32 generates a random float32 in the range [0.0, 1.0).

func (*PCG64) Float64

func (p *PCG64) Float64() float64

Float64 generates a random float64 in the range [0.0, 1.0).

func (*PCG64) Int

func (p *PCG64) Int(n int) int

Int generates a random integer in the range [0, n).

func (*PCG64) Int32

func (p *PCG64) Int32() int32

Int32 generates a random 32-bit signed integer.

func (*PCG64) Int64

func (p *PCG64) Int64() int64

Int64 generates a random 64-bit signed integer.

func (*PCG64) Marshal

func (p *PCG64) Marshal() ([]byte, error)

Marshal returns the binary encoding of the current state of the random number generator.

func (*PCG64) Next

func (p *PCG64) Next() uint64

Next generates a random 64-bit unsigned integer.

func (*PCG64) Reset

func (p *PCG64) Reset()

Reset resets the state of the random number generator to the seed value.

func (*PCG64) Seed

func (p *PCG64) Seed(seed uint64)

Seed initializes the state of the random number generator with the given seed value.

func (*PCG64) State

func (p *PCG64) State() (uint64, uint64, uint64, uint64)

State returns the current state of the random number generator.

func (*PCG64) Uint32

func (p *PCG64) Uint32() uint32

Uint32 generates a random 32-bit unsigned integer.

func (*PCG64) Unmarshal

func (p *PCG64) Unmarshal(data []byte) error

Unmarshal sets the state of the random number generator to the state represented by the input data.

type SafePCG64

type SafePCG64 struct {
	PCG64
	// contains filtered or unexported fields
}

SafePCG64 represents the state of a PCG-64 random number generator with a mutex to make it safe for concurrent use.

func NewSafe

func NewSafe() *SafePCG64

NewSafe creates a new safe PCG64 instance seeded with the current time.

func (*SafePCG64) Float64

func (p *SafePCG64) Float64() float64

Float64 generates a random float64 in the range [0.0, 1.0), which is safe for concurrent use.

func (*SafePCG64) Next

func (p *SafePCG64) Next() uint64

Next generates a random 64-bit unsigned integer, which is safe for concurrent use.

func (*SafePCG64) Reset

func (p *SafePCG64) Reset()

Reset resets the state of the random number generator to the seed value, which is safe for concurrent use.

func (*SafePCG64) Seed

func (p *SafePCG64) Seed(seed uint64)

Seed initializes the state of the random number generator with the given seed value, which is safe for concurrent use.

func (*SafePCG64) State

func (p *SafePCG64) State() (uint64, uint64, uint64, uint64)

State returns the current state of the random number generator, which is safe for concurrent use.

Jump to

Keyboard shortcuts

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