Use more robust 64-bit LCG for seeding CMWC internal state
This commit is contained in:
parent
4eb7971717
commit
9417d6ffdc
@ -24,12 +24,12 @@ class CMWCRandom(seed: Long = System.nanoTime()) : RandomGenerator, RandomSource
|
|||||||
this.seed = seed
|
this.seed = seed
|
||||||
carry = Integer.remainderUnsigned(seed.toInt(), CMWC_CARRY_MAX)
|
carry = Integer.remainderUnsigned(seed.toInt(), CMWC_CARRY_MAX)
|
||||||
|
|
||||||
// init state with regular LCG produced values
|
var lcg = seed
|
||||||
state[0] = seed.toInt()
|
|
||||||
state[1] = seed.shr(32).toInt()
|
|
||||||
|
|
||||||
for (i in 2 until state.size) {
|
// init state with regular LCG produced values
|
||||||
state[i] = 69069 * state[i - 2] + 362437
|
for (i in 1 until state.size) {
|
||||||
|
lcg = lcg * 6364136223846793005 + 1442695040888963407
|
||||||
|
state[i] = lcg.ushr(32).toInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
stateIndex = state.size - 1
|
stateIndex = state.size - 1
|
||||||
|
Loading…
Reference in New Issue
Block a user