/mtwist

Concise, tested Mersenne Twister in CoffeeScript/JavaScript

Primary LanguageC

mtwist

This is a concise implementation of the Mersenne Twister Pseudo-Random Number Generator (PRNG) for JavaScript.

The library:

The Mersenne Twister is not a cutting-edge PRNG. It is not cryptographically secure. It is very widely used, being the default PRNG for Excel, R, Python, Ruby and others. It is not without flaws.

Why would I use this?

  • The key use case is for reproducible pseudo-random sequences, which you get by manually seeding your PRNG
  • You could also use this because you want your random numbers generated the same way across all browsers and JavaScript engines

How do I use this?

x = Math.random();

becomes

import MersenneTwister from 'mtwist';

seed = 1234567890;  // an integer between 0 and 4294967295
m = new MersenneTwister(seed);

x = m.random();

Methods to produce evenly distributed integers in the ranges [0,n) and [m,n] are also provided.

For details, see index.ts.

Licence

© Copyright 2014 – 2021 George MacKerron and released under the MIT Licence.