From 9417d6ffdc8d5d6ba7307fb57da2254b9a14cdcb Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Wed, 5 Mar 2025 01:03:00 +0700 Subject: [PATCH] Use more robust 64-bit LCG for seeding CMWC internal state --- .../ru/dbotthepony/mc/otm/core/util/CMWCRandom.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/CMWCRandom.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/CMWCRandom.kt index 7ec103ac8..d37b80c50 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/CMWCRandom.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/CMWCRandom.kt @@ -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