Created
January 2, 2014 16:59
-
-
Save Protonk/8222366 to your computer and use it in GitHub Desktop.
The below is released under the GPL http://www.gnu.org/licenses/gpl.html
This file contains 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
//Webkit2's crazy invertible mapping generator | |
// Theory is here: http://dl.acm.org/citation.cfm?id=752741 | |
var xorshift = (function(seed) { | |
// We can't reach the maximal period inside JS because numbers above | |
// 2^53 aren't 'safe' | |
seed = seed || Math.round(Math.random() * Math.pow(2, 32)); | |
return { | |
rand : function() { | |
// creates randomness...somehow... | |
seed += (seed * seed) | 5; | |
// Shift off bits, discarding the sign. Discarding the sign is | |
// important because OR w/ 5 can give us + or - numbers. | |
return (seed >>> 32) / max; | |
} | |
}; | |
}(seed)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment