The Mersenne Twister Pseudo Random Number Generator
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

The Mersenne Twister Pseudo Random Number Generator

This is a mirror of my library hosted at

The Mersenne Twister is often regarded as the fastest pseudo-random number generator which passes almost all statistical tests.

The original C code isn't exactly beautiful, therefore I decided to write my own C++ class. .h plus .cpp file are under 100 lines even though there are tons of comments.

Basic usage:

#include "mersenne.h"
// create new Mersenne Twister
MersenneTwister prng(123456);
// generate two random 32-bit numbers
int x = prng();
int y = prng(); 

And for the fun of it, I converted the C++ code to Javascript and added two live demos, too.