From d326e45b3201ebee33c736e9899bd13e7159cbda Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Wed, 5 Mar 2025 07:58:48 +0700 Subject: [PATCH] Initialize carry using lcg instead of modulo divide seed --- .../kotlin/ru/dbotthepony/mc/otm/core/util/CMWCRandom.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 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 d37b80c50..bad5a002d 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 @@ -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() }