BitRandomSource .java

net.minecraft.world.level.levelgen.BitRandomSource (interface): members: DOUBLE_MULTIPLIER, FLOAT_MULTIPLIER, nextBoolean, nextDouble, nextFloat, nextLong.

net.minecraft.world.level.levelgeninterface62 linescommonextends RandomSource1.2 KB

API Surface (0)

No public/protected methods detected (fields or constants only).

Fields & Constants (2)

FLOAT_MULTIPLIER
DOUBLE_MULTIPLIER

String literals (1)

"Bound must be positive"

Code Graph: Dependencies (1)

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

Full Source

BitRandomSource.java62 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.levelgen;
2
3
import net.minecraft.util.RandomSource;
4
5
public interface BitRandomSource extends RandomSource {
6
	float FLOAT_MULTIPLIER = 5.9604645E-8F;
7
	double DOUBLE_MULTIPLIER = 1.110223E-16F;
8
9
	int next(final int bits);
10
11
	@Override
12
	default int nextInt() {
13
		return this.next(32);
14
	}
15
16
	@Override
17
	default int nextInt(final int bound) {
18
		if (bound <= 0) {
19
			throw new IllegalArgumentException("Bound must be positive");
20
		}
21
22
		if ((bound & bound - 1) == 0) {
23
			return (int)((long)bound * this.next(31) >> 31);
24
		}
25
26
		int sample;
27
		int modulo;
28
		do {
29
			sample = this.next(31);
30
			modulo = sample % bound;
31
		} while (sample - modulo + (bound - 1) < 0);
32
33
		return modulo;
34
	}
35
36
	@Override
37
	default long nextLong() {
38
		int upper = this.next(32);
39
		int lower = this.next(32);
40
		long shifted = (long)upper << 32;
41
		return shifted + lower;
42
	}
43
44
	@Override
45
	default boolean nextBoolean() {
46
		return this.next(1) != 0;
47
	}
48
49
	@Override
50
	default float nextFloat() {
51
		return this.next(24) * 5.9604645E-8F;
52
	}
53
54
	@Override
55
	default double nextDouble() {
56
		int upper = this.next(26);
57
		int lower = this.next(27);
58
		long combined = ((long)upper << 27) + lower;
59
		return combined * 1.110223E-16F;
60
	}
61
}
62

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