ThreadSafeLegacyRandomSource .java

net.minecraft.world.level.levelgen.ThreadSafeLegacyRandomSource (class): members: MODULUS_BITS, MODULUS_MASK, gaussianSource, MULTIPLIER, INCREMENT, fork.

net.minecraft.world.level.levelgenclass51 linescommon1.3 KB

Implements

API Surface (5)

RandomSource fork()
PositionalRandomFactory forkPositional()
void setSeed(final long seed)
int next(final int bits)
double nextGaussian()

Fields & Constants (6)

MODULUS_BITS
MODULUS_MASK
MULTIPLIER
INCREMENT
seed
gaussianSource

Code Graph: Dependencies (4)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

ThreadSafeLegacyRandomSource.java51 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.levelgen;
2
3
import java.util.concurrent.atomic.AtomicLong;
4
import net.minecraft.util.RandomSource;
5
6
@Deprecated
7
public class ThreadSafeLegacyRandomSource implements BitRandomSource {
8
	private static final int MODULUS_BITS = 48;
9
	private static final long MODULUS_MASK = 281474976710655L;
10
	private static final long MULTIPLIER = 25214903917L;
11
	private static final long INCREMENT = 11L;
12
	private final AtomicLong seed = new AtomicLong();
13
	private final MarsagliaPolarGaussian gaussianSource = new MarsagliaPolarGaussian(this);
14
15
	public ThreadSafeLegacyRandomSource(final long seed) {
16
		this.setSeed(seed);
17
	}
18
19
	@Override
20
	public RandomSource fork() {
21
		return new ThreadSafeLegacyRandomSource(this.nextLong());
22
	}
23
24
	@Override
25
	public PositionalRandomFactory forkPositional() {
26
		return new LegacyRandomSource.LegacyPositionalRandomFactory(this.nextLong());
27
	}
28
29
	@Override
30
	public void setSeed(final long seed) {
31
		this.seed.set((seed ^ 25214903917L) & 281474976710655L);
32
	}
33
34
	@Override
35
	public int next(final int bits) {
36
		long oldSeed;
37
		long nextSeed;
38
		do {
39
			oldSeed = this.seed.get();
40
			nextSeed = oldSeed * 25214903917L + 11L & 281474976710655L;
41
		} while (!this.seed.compareAndSet(oldSeed, nextSeed));
42
43
		return (int)(nextSeed >>> 48 - bits);
44
	}
45
46
	@Override
47
	public double nextGaussian() {
48
		return this.gaussianSource.nextGaussian();
49
	}
50
}
51

Decompiled Minecraft 26.3 source of ThreadSafeLegacyRandomSource (net/minecraft/world/level/levelgen/ThreadSafeLegacyRandomSource.java) with Mojang official mappings, stored verbatim on the site.