mersennetwister
Version:
A standalone, pure JavaScript implementation of the Mersenne Twister pseudo random number generator. Compatible with Node.js, requirejs and browser environments.
34 lines (30 loc) • 1.08 kB
HTML
<html>
<head>
<title>MersenneTwister example for browsers</title>
<script src="../../src/MersenneTwister.js"></script>
<script>
// Make this variable available in the global scope so people can play around with it in the console.
var mt;
// Instantiation
mt = new MersenneTwister(); // seed randomly
mt = new MersenneTwister(42); // seed manually
// available methods:
mt.int();
mt.int31();
mt.rnd();
mt.rndHiRes();
mt.real();
mt.realx();
// reinitialize with specific seed
mt.seed(42);
mt.seedArray([42, 23, 17]);
// or you can just use the static "random" method as a drop-in replacement for Math.random
MersenneTwister.random();
</script>
</head>
<body>
<p>Check the source code of this page to see how the Mersenne Twister is to be used.</p>
<script src="script.js"></script>
</body>
</html>