rng

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: MIT Imports: 0 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package rng is the deterministic PRNG every random draw in the simulation routes through. It is a direct port of the engine's Mulberry32 generator: a tiny splittable PRNG with a single uint32 of state, adequate for aim jitter, target selection and particle offsets. Not cryptographic.

Determinism is the point — given the same seed and the same sequence of draws, the server and a wasm client produce identical results, which is what lets client-side prediction agree with the authoritative simulation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Rng

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

Rng holds a single uint32 of Mulberry32 state.

func New

func New(seed uint32) *Rng

New constructs an Rng from a seed. A zero seed degenerates to a fixed point at zero, so it is offset to the golden-ratio constant, matching the JS port.

func (*Rng) Float

func (r *Rng) Float() float64

Float returns a value in [0, 1), the integer-free analogue of Math.random.

func (*Rng) Fork

func (r *Rng) Fork() *Rng

Fork derives an independent child stream from this generator's next draw, so adding or removing one consumer does not perturb every other consumer's sequence.

func (*Rng) Next32

func (r *Rng) Next32() uint32

Next32 advances the generator and returns a raw uint32. Every other helper sits on top of this.

func (*Rng) Range

func (r *Rng) Range(lo, hi int) int

Range returns a uniform integer in [lo, hi] inclusive, matching the COB rand(lo, hi) semantics. The bounds may be given in either order.

func (*Rng) Restore

func (r *Rng) Restore(s uint32)

Restore sets the state from a prior Snapshot.

func (*Rng) Snapshot

func (r *Rng) Snapshot() uint32

Snapshot returns the current state for replay checkpointing.

Jump to

Keyboard shortcuts

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