Last active
December 27, 2020 21:41
-
-
Save i001962/178b4a46ce737c204f58e3688afc6f3a to your computer and use it in GitHub Desktop.
generate n random numbers from the same seed
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
| // I haven't die hardered any of this. HDR passed. I wrote the js code based on what I found in Excel formula. CAUTION | |
| // seed = 6345484 // change when you want a new starting point for a stream of random numbers | |
| // PM_Index = 0 // where on stream do you want to grab random number from? Increment to n for n seeded random numbers | |
| function HDRando(seed, PM_Index) { | |
| const largePrime = 2147483647; | |
| const million = 1000000; | |
| const tenMillion = 10000000; | |
| // Do we need this in js? is there a modulo? | |
| function MOD(n, m) { | |
| var remain = n % m; | |
| return Math.floor(remain >= 0 ? remain : remain + m); | |
| } | |
| let randi = | |
| (MOD( | |
| (MOD( | |
| (seed + million) ^ (2 + (seed + million) * (PM_Index + tenMillion)), | |
| 99999989 | |
| ) + | |
| 1000007) * | |
| (MOD( | |
| (PM_Index + tenMillion) ^ | |
| (2 + | |
| (PM_Index + tenMillion) * | |
| MOD( | |
| (seed + million) ^ | |
| (2 + (seed + million) * (PM_Index + tenMillion)), | |
| 99999989 | |
| )), | |
| 99999989 | |
| ) + | |
| 1000013), | |
| largePrime | |
| ) + | |
| 0.5) / | |
| largePrime; | |
| return randi; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment