mersenne-twister
Mersenne twister pseudorandom number generator
Last updated 4 years ago by boo1ean .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install mersenne-twister 
SYNC missed versions from official npm registry.

Pseudorandom number generator Build Status

Mersenne Twister pseudorandom number generator.

Origin source (generator interface was changed)

Algorithm - http://en.wikipedia.org/wiki/Mersenne_twister

Installation

$ npm install mersenne-twister

Usage

var MersenneTwister = require('mersenne-twister');
var generator = new MersenneTwister();

// Generates a random number on [0,1) real interval (same interval as Math.random)
generator.random();

// [0, 4294967295]
generator.random_int();

// [0,1]
generator.random_incl();

// (0,1)
generator.random_excl();

// [0,1) with 53-bit resolution
generator.random_long();

// [0, 2147483647]
generator.random_int31();

Seeding

If you want to use a specific seed in order to get a repeatable random sequence, pass an integer into the constructor:

var generator = new MersenneTwister(123);

and that will always produce the same random sequence.

Also you can do it on existing generator instance:

generator.init_seed(123);

License

See source

Current Tags

  • 1.1.0                                ...           latest (4 years ago)

3 Versions

  • 1.1.0                                ...           4 years ago
  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago

Copyright 2014 - 2016 © taobao.org |