summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorsiddharth <s@ricketyspace.net>2021-08-17 20:31:37 -0400
committersiddharth <s@ricketyspace.net>2021-08-17 20:31:37 -0400
commitbcabfa560e1b65c375f5a9ae91cb6f718c5eb28e (patch)
tree527bf83b19a13d030d99eb6e4fd9aa496a511eb9 /lib
parentbde6b04f7e3f29550a9db967ab929d589869c379 (diff)
lib: add MTRand.UnTemper
Diffstat (limited to 'lib')
-rw-r--r--lib/rng.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/rng.go b/lib/rng.go
index 94cbd6c..c39b83a 100644
--- a/lib/rng.go
+++ b/lib/rng.go
@@ -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
+}