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

0.1.4 • Public • Published

node-lcg

Seedable and splittable (LCG) Random Number Generator

A seedable linear congruential generator that supports splitting as described in the paper "Distributed random number generation" by F. Warren Burton and Rex L. Page.

Installation

npm install lcg

Usage

Example

import {Random} from 'lcg';
 
const seed = Math.random() * (1 << 32);
 
const random = new Random(seed);
const value = random.get();
const nextRandom = random.next();
const nextValue = nextRandom.get();

API

Building New Generators

Random#next()

Returns a new generator by perturbing the random state.

Random#split()

Returns an array of two new independent generators by splitting the random state.

Retrieving Values

Random#get()

Produces a real-valued random number x, where 0 <= x < 1.

Random#getIntegerBetween(min, max)

Produces an integer-valued random number x, where min <= x <= max.

Package Sidebar

Install

npm i lcg

Weekly Downloads

4

Version

0.1.4

License

MIT

Last publish

Collaborators

  • srijs