replayable-random
    TypeScript icon, indicating that this package has built-in type declarations

    0.4.1 • Public • Published

    Replayable Random

    travis NPM version

    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:

    import { alea } from "replayable-random"

    Derive the first state from a string (printable ASCII) seed:

    // Pure functional API
    const g = alea.from("printable-ascii-seed")
     
    // Imperative API
    const mutG = alea.mutFrom("printable-ascii-seed")

    Choose a distribution

    Import distrib:

    import { distrib } from "replayable-random"

    Choose a distribution and generate your first random numbers. e.g. to generate two integers between -4 (inclusive) and 5 (excluded):

    // Pure functional API
    const [n1, g1] = distrib.i32Between(-4)(5)(g)
    const [n2, g2] = distrib.i32Between(-4)(5)(g1)
     
    // Imperative API
    let n
    = distrib.mutI32Between(-4)(5)(mutG)
    = distrib.mutI32Between(-4)(5)(mutG)
     
    // Math.random compatibility
    = distrib.mutI32Between(-4)(5)(Math)
    = distrib.mutI32Between(-4)(5)(Math)

    Documentation

    Install

    npm i replayable-random

    DownloadsWeekly Downloads

    10

    Version

    0.4.1

    License

    Zlib

    Unpacked Size

    270 kB

    Total Files

    230

    Last publish

    Collaborators

    • avatar