From 2471abdd1f5905a72a4015bef18cd3a7e77bc041 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Sun, 9 Mar 2025 21:19:43 +0700 Subject: [PATCH] Fix gjrand64 initialization --- gradle.properties | 2 +- .../kommons/random/GJRAND64Random.kt | 20 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 7c3f023..32fcfca 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ kotlin.code.style=official specifyKotlinAsDependency=false projectGroup=ru.dbotthepony.kommons -projectVersion=3.5.1 +projectVersion=3.5.2 guavaDepVersion=33.0.0 gsonDepVersion=2.8.9 diff --git a/src/main/kotlin/ru/dbotthepony/kommons/random/GJRAND64Random.kt b/src/main/kotlin/ru/dbotthepony/kommons/random/GJRAND64Random.kt index 8da65a0..bf304d8 100644 --- a/src/main/kotlin/ru/dbotthepony/kommons/random/GJRAND64Random.kt +++ b/src/main/kotlin/ru/dbotthepony/kommons/random/GJRAND64Random.kt @@ -21,9 +21,27 @@ open class GJRAND64Random protected constructor( protected var s3: Long, marker: Nothing? ) : RandomGenerator { - constructor(seed0: Long, seed1: Long) : this(seed0, seed1, SEED2_INIT, SEED3_INIT, null) + constructor(seed0: Long, seed1: Long) : this(seed0, seed1, SEED2_INIT, SEED3_INIT, null) { + for (i in 0 until 14) + nextLong() + } + constructor(seed: Long) : this(seed, 0L) + protected fun reinitialize(seed: Long) { + reinitialize(seed, 0L) + } + + protected fun reinitialize(seed0: Long, seed1: Long) { + s0 = seed0 + s1 = seed1 + s2 = SEED2_INIT + s3 = SEED3_INIT + + for (i in 0 until 14) + nextLong() + } + final override fun nextLong(): Long { s1 += s2 s0 = s0.rotateLeft(32)