Skip to content
Switch branches/tags
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

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.