Initialize carry using lcg instead of modulo divide seed

This commit is contained in:
DBotThePony 2025-03-05 07:58:48 +07:00
parent 9417d6ffdc
commit d326e45b32
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -22,8 +22,6 @@ class CMWCRandom(seed: Long = System.nanoTime()) : RandomGenerator, RandomSource
override fun setSeed(seed: Long) {
this.seed = seed
carry = Integer.remainderUnsigned(seed.toInt(), CMWC_CARRY_MAX)
var lcg = seed
// init state with regular LCG produced values
@ -32,6 +30,11 @@ class CMWCRandom(seed: Long = System.nanoTime()) : RandomGenerator, RandomSource
state[i] = lcg.ushr(32).toInt()
}
do {
lcg = lcg * 6364136223846793005 + 1442695040888963407
carry = lcg.ushr(32).toInt()
} while(carry !in 0 until CMWC_CARRY_MAX)
stateIndex = state.size - 1
gaussian.reset()
}