MarsagliaPolarGaussian .java

net.minecraft.world.level.levelgen.MarsagliaPolarGaussian (class): members: haveNextNextGaussian, nextNextGaussian, nextGaussian, randomSource, reset.

net.minecraft.world.level.levelgenclass40 linescommon1.0 KB

API Surface (2)

void reset()
double nextGaussian()

Fields & Constants (3)

randomSource
nextNextGaussian
haveNextNextGaussian

Code Graph: Dependencies (2)

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

Full Source

MarsagliaPolarGaussian.java40 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.levelgen;
2
3
import net.minecraft.util.Mth;
4
import net.minecraft.util.RandomSource;
5
6
public class MarsagliaPolarGaussian {
7
	public final RandomSource randomSource;
8
	private double nextNextGaussian;
9
	private boolean haveNextNextGaussian;
10
11
	public MarsagliaPolarGaussian(final RandomSource randomSource) {
12
		this.randomSource = randomSource;
13
	}
14
15
	public void reset() {
16
		this.haveNextNextGaussian = false;
17
	}
18
19
	public double nextGaussian() {
20
		if (this.haveNextNextGaussian) {
21
			this.haveNextNextGaussian = false;
22
			return this.nextNextGaussian;
23
		}
24
25
		double x;
26
		double y;
27
		double radiusSquared;
28
		do {
29
			x = 2.0 * this.randomSource.nextDouble() - 1.0;
30
			y = 2.0 * this.randomSource.nextDouble() - 1.0;
31
			radiusSquared = Mth.square(x) + Mth.square(y);
32
		} while (radiusSquared >= 1.0 || radiusSquared == 0.0);
33
34
		double multiplier = Math.sqrt(-2.0 * Math.log(radiusSquared) / radiusSquared);
35
		this.nextNextGaussian = y * multiplier;
36
		this.haveNextNextGaussian = true;
37
		return x * multiplier;
38
	}
39
}
40

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