SingleThreadedRandomSource .java

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

net.minecraft.world.level.levelgenclass52 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

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

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