From bcabfa560e1b65c375f5a9ae91cb6f718c5eb28e Mon Sep 17 00:00:00 2001 From: siddharth Date: Tue, 17 Aug 2021 20:31:37 -0400 Subject: lib: add MTRand.UnTemper --- lib/rng.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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 +} -- cgit v1.2.3