class

Crowbar::PRNG

Inherits Reference < Object

High-performance, deterministic 64-bit pseudo-random number generator. Uses Xoshiro256++ seeded via SplitMix64 for uniform statistical properties, long period (2^256 - 1), and complete reproducibility across platforms.

Constructors

new(seed : UInt64 = PRNG.default_seed)
Source

Class methods

default_seed
Source

Instance methods

choice(array : Array(T)) : T forall T

Random element from array

Source
choice?(array : Array(T)) : T | Nil forall T
Source
next_u32

Generate next 32-bit unsigned integer

Source
next_u64

Generate next raw 64-bit unsigned integer using Xoshiro256++

Source
rand(max : Int) : Int32

Random integer in [0, max)

Source
rand(range : Range(Int32, Int32)) : Int32

Random integer within inclusive range (e.g. 1..10) or exclusive range (e.g. 0...5)

Source
rand_bool(prob : Float64 = 0.5) : Bool

Returns true with probability p (default 0.5)

Source
rand_float

Random Float64 in [0.0, 1.0)

Source
rand_log(max_power : Int32 = 14) : Int32

Log-scale random distribution (useful for repeats, burst lengths, and byte counts) Generates values from 1 up to 2^max_power with logarithmic bias towards smaller values

Source
sample(array : Array(T), count : Int32) : Array(T) forall T

Reservoir sample or simple sample

Source
seed
Source
seed=(new_seed : UInt64)
Source
seek(offset : Int) : Nil

Fast-forwards PRNG state by offset iterations

Source
shuffle(array : Array(T)) : Array(T) forall T

Non-destructive shuffle

Source
shuffle!(array : Array(T)) : Array(T) forall T

Shuffle array in-place (Fisher-Yates) and return it

Source