Created
May 10, 2014 05:53
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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