Module

Hylograph.Forces.Random

Package
purescript-hylograph-forces
Repository
afcondon/purescript-hylograph-forces

d3-force's random source: the linear congruential generator of lcg.js and the jiggle that separates coincident nodes.

Ported from d3-force 3.0.0 (ISC, Copyright 2010-2021 Mike Bostock); see LICENSE.

The generator is a pure step on a Seed, so the tree walks can thread it as a loop variable; a Source is the same seed in a Ref, shared by the forces of one simulation the way d3 shares one random function.

#Seed Source

newtype Seed

The generator's state: an integer in [0, 2^32), held as a Number because the multiplication needs 53 bits.

#Source Source

type Source = Ref Seed

A seed shared between forces.

#lcg Source

lcg :: Effect Source

d3's lcg(): a fresh source.

#initialSeed Source

initialSeed :: Seed

d3 starts every generator at 1.

#advance Source

advance :: Seed -> Seed

One step: s = (a * s + c) % m.

#jiggle Source

jiggle :: Seed -> Number

d3's jiggle(random), read from a seed that has just been advanced: (s / m - 0.5) * 1e-6.

#draw Source

draw :: Source -> Effect Number

Advance a shared source and return its jiggle.