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
|
||||
carry = Integer.remainderUnsigned(seed.toInt(), CMWC_CARRY_MAX)
|
||||
|
||||
// init state with regular LCG produced values
|
||||
state[0] = seed.toInt()
|
||||
state[1] = seed.shr(32).toInt()
|
||||
var lcg = seed
|
||||
|
||||
for (i in 2 until state.size) {
|
||||
state[i] = 69069 * state[i - 2] + 362437
|
||||
// init state with regular LCG produced values
|
||||
for (i in 1 until state.size) {
|
||||
lcg = lcg * 6364136223846793005 + 1442695040888963407
|
||||
state[i] = lcg.ushr(32).toInt()
|
||||
}
|
||||
|
||||
stateIndex = state.size - 1
|
||||
|
Loading…
Reference in New Issue
Block a user