Rng

class Rng
rng.ts:13

Members

constructor

constructor(seed: Seed) → Rng
seedSeed
Undocumented

bool

bool(probability: number) → boolean
probabilitynumber
Undocumented

fork

fork(label: string) → Rng

Branch off an independent stream by label.

Use this rather than continuing to draw from the parent when the number of draws a sub-generator makes might change: a branch keeps the parent's subsequent values stable.

labelstring
Undocumented

fromSeedstatic

fromSeed(seed: Seed) → Rng
seedSeed
Undocumented

gaussian

gaussian(mean: number, stdDev: number) → number

Standard normal, Box–Muller. Both draws are consumed so streams stay aligned.

meannumber
Undocumented
stdDevnumber
Undocumented

int

int(min: number, max: number) → number

Uniform integer in [min, max].

minnumber
Undocumented
maxnumber
Undocumented

next

next() → number

Uniform in [0, 1) with 32 bits of resolution.

nextFloat53

nextFloat53() → number

Uniform in [0, 1) with the full 53 bits a double can hold.

nextUint32

nextUint32() → number

Uniform uint32.

pick

pick<T>(items: readonly T[]) → T
itemsreadonly T[]
Undocumented

powerLaw

powerLaw(alpha: number, min: number, max: number) → number

Power-law sample in [min, max] with exponent alpha, by inverse CDF. Stellar masses and asteroid sizes both want this rather than a uniform.

alphanumber
Undocumented
minnumber
Undocumented
maxnumber
Undocumented

range

range(min: number, max: number) → number

Uniform in [min, max).

minnumber
Undocumented
maxnumber
Undocumented

shuffle

shuffle<T>(items: T[]) → T[]

Fisher–Yates, in place.

itemsT[]
Undocumented

unitVector

unitVector() → { x: number; y: number; z: number }

Uniformly distributed direction on the unit sphere (Marsaglia).

weightedIndex

weightedIndex(weights: readonly number[]) → number

Index into a weight table, proportional to the weights.

weightsreadonly number[]
Undocumented