Replayable Random
Replayable Random enables to generate reproducible sequences of pseudo-random numbers. The librray provides several seeded generators and multiple distributions.
Highlights
Choose an API
Replayable Random provides both a pure functional API and an imperative API. The pure functional API is well-suited for projects that embrace immutability and purity. It uses a copy-on-write startegy to achieve better performances.
Pay only for what you use
Replayable Random is designed to take advantage of modern dead code elimination techniques, especially tree shaking. Using bundlers such as rollup, your bundles can contain only the functions which are actually used. Future versions of Replayable Random can integrate new functions without affecting the size of your bundles.
Easily extensible
Replayable Random have well-defined interfaces and provides hightly composable helpers and distributions.
Getting started
Install replayable-random as a dependency:
npm install replayable-random
Choose a random generator
Import a genrator using its name, e.g. alea
:
Derive the first state from a string (printable ASCII) seed:
// Pure functional APIconst g = alea // Imperative APIconst mutG = alea
Choose a distribution
Import distrib
:
Choose a distribution and generate your first random numbers. e.g. to generate two integers between -4 (inclusive) and 5 (excluded):
// Pure functional APIconst n1 g1 = distrib5gconst n2 g2 = distrib5g1 // Imperative APIlet nn = distrib5mutGn = distrib5mutG // Math.random compatibilityn = distrib5Mathn = distrib5Math
Documentation
- Available PRNGs
- Available distributions
- Best practices
- Write your own PRNG (coming soon)
- Write your own distribution (coming soon)