random
nimony/lib/std/random.nim
A fast, non-cryptographic pseudo-random number generator (xoroshiro128+).
Each proc has two forms: one taking an explicit Rand state, and one using a shared default generator. The default-generator procs are not thread-safe — give each thread its own Rand via initRand.
type Rand = object a0: uint64 a1: uint64
func next(r: var Rand): uint64Returns the next raw random
uint64and advancesr.proc skipRandomNumbers(r: var Rand)Advances
rby 2^64 steps — used to split a generator into non-overlapping subsequences for parallel work.proc initRand(seed: int64): RandCreates a
Randseeded withseed. The same seed always yields the same sequence.seed == 0is mapped to a fixed non-zero value.proc rand(r: var Rand; max: int64): int64Random integer in
0 .. max(inclusive) usingr.proc rand(max: int64): int64Random integer in
0 .. maxusing the default generator.proc rand(r: var Rand; max: float64): float64Random float in
0.0 .. maxusingr.proc rand(max: float64): float64Random float in
0.0 .. maxusing the default generator.proc rand(r: var Rand; x: HSlice): int64Random integer in the inclusive range
xusingr.proc rand(x: HSlice): int64Random integer in the inclusive range
xusing the default generator.proc rand(r: var Rand; x: HSlice): float64Random float in the inclusive range
xusingr.proc rand(x: HSlice): float64Random float in the inclusive range
xusing the default generator.proc sample(r: var Rand; a: openArray[T]): TReturns a random element of
ausingr.proc sample(a: openArray[T]): TReturns a random element of
ausing the default generator.proc shuffle(r: var Rand; x: var openArray[T])Fisher-Yates shuffle of
xin place usingr.proc shuffle(x: var openArray[T])Shuffles
xin place using the default generator.proc randomize(seed: int64)Reseeds the default generator with
seed.