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 a41a68b54..767637340 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 @@ -4,10 +4,11 @@ import net.minecraft.util.Mth import net.minecraft.util.RandomSource import net.minecraft.world.level.levelgen.MarsagliaPolarGaussian import net.minecraft.world.level.levelgen.PositionalRandomFactory +import net.minecraft.world.level.levelgen.RandomSupport import java.lang.StringBuilder import java.util.random.RandomGenerator -class CMWCRandom(seed: Long = System.nanoTime()) : RandomGenerator, RandomSource { +class CMWCRandom(seed: Long = RandomSupport.generateUniqueSeed()) : RandomGenerator, RandomSource { private val state = IntArray(CMWC_STATE_SIZE) private var carry = 0 private var stateIndex = 0 diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/LCG64Random.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/LCG64Random.kt index 271b8a6a9..7cac69c0d 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/LCG64Random.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/LCG64Random.kt @@ -4,13 +4,14 @@ import net.minecraft.util.Mth import net.minecraft.util.RandomSource import net.minecraft.world.level.levelgen.MarsagliaPolarGaussian import net.minecraft.world.level.levelgen.PositionalRandomFactory +import net.minecraft.world.level.levelgen.RandomSupport import java.lang.StringBuilder import java.util.random.RandomGenerator // different from LegacyRandomSource minecraft uses in meaning that this class use different constants // and always use upper 32 bits instead of implementing BitRandomSource // AND it uses all bits from provided seed -class LCG64Random(private var seed: Long = System.nanoTime()) : RandomGenerator, RandomSource { +class LCG64Random(private var seed: Long = RandomSupport.generateUniqueSeed()) : RandomGenerator, RandomSource { private val gaussian = MarsagliaPolarGaussian(this) override fun setSeed(seed: Long) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/Xoshiro256SSRandom.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/Xoshiro256SSRandom.kt index e14e7ed02..472c89b27 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/Xoshiro256SSRandom.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/Xoshiro256SSRandom.kt @@ -5,6 +5,7 @@ import net.minecraft.util.Mth import net.minecraft.util.RandomSource import net.minecraft.world.level.levelgen.MarsagliaPolarGaussian import net.minecraft.world.level.levelgen.PositionalRandomFactory +import net.minecraft.world.level.levelgen.RandomSupport import java.lang.StringBuilder import java.util.random.RandomGenerator @@ -16,10 +17,12 @@ class Xoshiro256SSRandom( ) : RandomGenerator, RandomSource { private val gaussian = MarsagliaPolarGaussian(this) - constructor(seed: Long = System.nanoTime()) : this(1L, 2L, 3L, 4L) { + constructor(seed: Long) : this(1L, 2L, 3L, 4L) { setSeed(seed) } + constructor() : this(RandomSupport.generateUniqueSeed(), RandomSupport.generateUniqueSeed(), RandomSupport.generateUniqueSeed(), RandomSupport.generateUniqueSeed()) + override fun setSeed(seed: Long) { val rng = LCG64Random(seed) s0 = rng.nextLong()