1.0.0 • Published 3 years ago

@no-day/fp-ts-lcg v1.0.0

Weekly downloads
-
License
-
Repository
-
Last release
3 years ago

fp-ts-lcg

A seeded pseudorandom number generator based on the linear congruential generator algorithm.

A port of purescript-lcg.

Install

Uses fp-ts as a peer dependency.

npm install fp-ts @no-day/fp-ts-lcg

JavaScript Example

// index.js

const lcg = require("@no-day/lcg");

let seed = lcg.mkSeed(3532);

for (let i = 0; i < 10; i++) {
  console.log(lcg.unSeed(seed));
  seed = lcg.lcgNext(seed);
}

Result:

node index.js
3533
170541443
901176102
1242866010
134522471
1691132760
373584549
879580920
351404483
1819954887

The generated seeds are pseudo random. Meaning, that whenever the same initial seed is chosen (here it's 3532), the results of the next seeds will be always the same. The generated seeds will be equally distributed in the range of lcg.seedMin and lcg.seedMax.

Dcoumentation