Skip to content

Instantly share code, notes, and snippets.

@mindoftea
Created May 10, 2014 05:53
Show Gist options
  • Save mindoftea/46898281a61fd6509c1e to your computer and use it in GitHub Desktop.
Save mindoftea/46898281a61fd6509c1e to your computer and use it in GitHub Desktop.
A simple seeded pseudo-random number generator implemented in JavaScript using the Blum Blum Shub method.
var SeededRand = function(seed, mod1, mod2)
{
return function()
{
seed = (seed*seed) % (mod1*mod2);
return seed/(mod1*mod2);
};
};
var rand = SeededRand(seed, mod1, mod2);
// Creates a new random number generator with the given seeds.
rand();
// Spits out a new random value each time it is called.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment