Skip to content

@graphty/layout / index / Lcg

Class: Lcg ​

Defined in: simulation/seed.ts:24

The port's RandomNumberGenerator, bit for bit: seed || Math.floor(Math.random() * 1000000) (seed 0 / null = unseeded, the quirk preserved), state = seed % m, next = (a * state + c) % m, value = state / m. The product a * state stays below 2^53 (a < 2^18, state < 2^35), so every step is exact in f64, as it is in the port.

Constructors ​

Constructor ​

new Lcg(seed): Lcg

Defined in: simulation/seed.ts:34

Creates the generator; a seed of 0, -0, NaN or null means unseeded (the port's seed || random quirk).

Parameters ​

seed ​

number | null

the seed, or null for a random seed

Returns ​

Lcg

Properties ​

seed ​

readonly seed: number

Defined in: simulation/seed.ts:26

The seed actually used (a random one when unseeded).

Methods ​

next() ​

next(): number

Defined in: simulation/seed.ts:43

Next value in [0, 1).

Returns ​

number

state / m after one LCG step