rng

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package rng provides a fast, per-instance random source. Unlike the stdlib global rand, every Generator owns its own *Rand, so concurrent goroutines never contend on a shared mutex — the classic faker bottleneck.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Rand

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

Rand is a lightweight, non-cryptographic PRNG. Not safe for concurrent use; give each goroutine its own via Fork or a pool.

func New

func New(seed uint64) *Rand

New returns a Rand seeded deterministically.

func (*Rand) Bool

func (r *Rand) Bool(p float64) bool

Bool returns true with the given probability.

func (*Rand) Digits

func (r *Rand) Digits(n int) string

Digits returns a string of n random decimal digits.

func (*Rand) Float64

func (r *Rand) Float64() float64

Float64 returns a float in [0,1).

func (*Rand) Fork

func (r *Rand) Fork(i uint64) *Rand

Fork derives a new independent Rand for index i. It is a PURE function of this Rand's seed and i — it does not consume this Rand's stream — so record i is identical no matter the order or goroutine it is produced in.

func (*Rand) IntRange

func (r *Rand) IntRange(min, max int) int

IntRange returns an int in [min,max].

func (*Rand) Intn

func (r *Rand) Intn(n int) int

Intn returns a non-negative int in [0,n). Panics if n<=0.

func (*Rand) NormFloat64

func (r *Rand) NormFloat64() float64

NormFloat64 returns a standard-normal (mean 0, stddev 1) sample via Box-Muller. Used by the dist package for Normal/LogNormal.

func (*Rand) Pick

func (r *Rand) Pick(n int) int

Pick returns a random element index for a slice of length n.

func (*Rand) Uint64

func (r *Rand) Uint64() uint64

Uint64 returns a random 64-bit value.

Jump to

Keyboard shortcuts

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