Allow to "initialize" xoshiro with zero seed, and provide "raw" initialization

This commit is contained in:
DBotThePony 2025-03-06 18:20:26 +07:00
parent c40f9a2c57
commit 1dd57065c9
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -6,7 +6,6 @@ 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
/**
@ -22,12 +21,12 @@ class Xoshiro256SSRandom private constructor(
private val gaussian = MarsagliaPolarGaussian(this)
init {
require(
s0 != 0L ||
s1 != 0L ||
s2 != 0L ||
s3 != 0L
) { "Xoshiro can't operate with seed being entirely zero" }
if (s0 or s1 or s2 or s3 == 0L) {
s0 = 0x73CF3D83FFF44FF3L
s1 = 0x6412312B70F3CD37L
s2 = -0X6BB4C4E1327BFDCFL
s3 = -0X4BE0F5BB5F3F5240L
}
}
constructor(s0: Long, s1: Long, s2: Long, s3: Long) : this(s0, s1, s2, s3, null) {
@ -129,4 +128,11 @@ class Xoshiro256SSRandom private constructor(
throw UnsupportedOperationException()
}
}
companion object {
@JvmStatic
fun raw(s0: Long, s1: Long, s2: Long, s3: Long): Xoshiro256SSRandom {
return Xoshiro256SSRandom(s0, s1, s2, s3, null)
}
}
}