JSPM

replayable-random

0.4.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 664
  • Score
    100M100P100Q100682F
  • License Zlib

Reproducible sequences of pseudo random numbers for TypeScript and JavaScript

Package Exports

  • replayable-random

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (replayable-random) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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
n = distrib.mutI32Between(-4)(5)(mutG)
n = distrib.mutI32Between(-4)(5)(mutG)

// Math.random compatibility
n = distrib.mutI32Between(-4)(5)(Math)
n = distrib.mutI32Between(-4)(5)(Math)

Documentation