diff options
author | siddharth <s@ricketyspace.net> | 2021-08-17 20:31:37 -0400 |
---|---|---|
committer | siddharth <s@ricketyspace.net> | 2021-08-17 20:31:37 -0400 |
commit | bcabfa560e1b65c375f5a9ae91cb6f718c5eb28e (patch) | |
tree | 527bf83b19a13d030d99eb6e4fd9aa496a511eb9 /lib/rng.go | |
parent | bde6b04f7e3f29550a9db967ab929d589869c379 (diff) |
lib: add MTRand.UnTemper
Diffstat (limited to 'lib/rng.go')
-rw-r--r-- | lib/rng.go | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -71,3 +71,24 @@ func (r *MTRand) twist() { } r.index = 0 } + +func (r *MTRand) UnTemper(y uint32) uint32 { + y = y ^ (y >> mtCoefL) + + y0 := y + y = y0 ^ ((y0 << mtCoefT) & mtCoefC) + y = y0 ^ ((y << mtCoefT) & mtCoefC) + + y0 = y + y = y0 ^ ((y0 << mtCoefS) & mtCoefB) + y = y0 ^ ((y << mtCoefS) & mtCoefB) + y = y0 ^ ((y << mtCoefS) & mtCoefB) + y = y0 ^ ((y << mtCoefS) & mtCoefB) + + y0 = y + y = y0 ^ (y0 >> mtCoefU) + y = y0 ^ (y >> mtCoefU) + + y = 0xFFFFFFFF & y + return y +} |