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.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE
mersenne.cpp
mersenne.h
mersenne.js
original.c
readme.md

readme.md

The Mersenne Twister Pseudo Random Number Generator

This is a mirror of my library hosted at https://create.stephan-brumme.com/mersenne-twister/

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.