This commit is contained in:
DBotThePony 2025-03-12 18:28:36 +07:00
parent 9836fa0088
commit 60cbe70041
Signed by: DBot
GPG Key ID: DCC23B5715498507
3 changed files with 19 additions and 15 deletions

View File

@ -34,7 +34,7 @@ mod_name=Better Random
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=BSD 2 Clause
# The mod version. See https://semver.org/
mod_version=1.3.2
mod_version=1.3.3
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html

View File

@ -73,10 +73,25 @@ public class GJRAND64RandomSource implements RandomGenerator, RandomSource {
s3 = 0L;
for (int i = 0; i < 14; i++) {
nextLong();
round();
}
}
protected final long round() {
s1 += s2;
s0 = Long.rotateLeft(s0, 32);
s2 ^= s1;
s3 += 0x55aa96a5L;
s0 += s1;
s2 = Long.rotateLeft(s2, 23);
s1 ^= s0;
s0 += s2;
s1 = Long.rotateLeft(s1, 19);
s2 += s0;
s1 += s3;
return s0;
}
@Override
public @NotNull RandomSource fork() {
return new GJRAND64RandomSource(nextLong(), nextLong());
@ -147,18 +162,7 @@ public class GJRAND64RandomSource implements RandomGenerator, RandomSource {
@Override
public long nextLong() {
s1 += s2;
s0 = Long.rotateLeft(s0, 32);
s2 ^= s1;
s3 += 0x55aa96a5L;
s0 += s1;
s2 = Long.rotateLeft(s2, 23);
s1 ^= s0;
s0 += s2;
s1 = Long.rotateLeft(s1, 19);
s2 += s0;
s1 += s3;
return s0;
return round();
}
public static class Positional implements PositionalRandomFactory {

View File

@ -31,7 +31,7 @@ public class SynchronizedGJRAND64RandomSource extends GJRAND64RandomSource {
@Override
public long nextLong() {
lock.lock();
long result = super.nextLong();
long result = super.round();
lock.unlock();
return result;
}