rng

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package rng provides deterministic seeded random streams keyed by a composite SeedKey (tick, actor, event-seq, purpose). Same SeedKey → same output sequence, which is the foundation for replayable matches, forensic audit, and reproducible loot rolls.

Backed by math/rand/v2's ChaCha8 source. Sub-streams are derived from the master seed + SeedKey via a deterministic mixing function, so streams are independent without sharing state.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SeedKey

type SeedKey struct {
	Tick     uint64
	ActorID  uint64
	EventSeq uint32
	Purpose  string
}

SeedKey identifies a derived stream. Two streams with the same SeedKey (under the same master seed) produce identical output sequences — that is the load-bearing property for replay and audit.

type Source

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

Source owns the master seed and mints typed Streams.

func New

func New(master [32]byte) *Source

New returns a Source seeded with the given 32-byte master seed.

func (*Source) Sub

func (s *Source) Sub(key SeedKey) *Stream

Sub derives an independent Stream from the master + key. Deterministic: same Source + same SeedKey → byte-identical output.

type Stream

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

Stream is a deterministic random source derived from a SeedKey.

func (*Stream) Float64

func (s *Stream) Float64() float64

func (*Stream) IntN

func (s *Stream) IntN(n int) int

IntN returns a uniform random int in [0, n).

func (*Stream) Key

func (s *Stream) Key() SeedKey

Key returns the SeedKey this stream was derived from, for audit emission.

func (*Stream) Shuffle

func (s *Stream) Shuffle(n int, swap func(i, j int))

Shuffle randomly reorders n elements via swap(i, j).

func (*Stream) Uint64

func (s *Stream) Uint64() uint64

Jump to

Keyboard shortcuts

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