| 1 | package net.minecraft.util;
|
| 2 |
|
| 3 | import io.netty.util.internal.ThreadLocalRandom;
|
| 4 | import net.minecraft.world.level.levelgen.LegacyRandomSource;
|
| 5 | import net.minecraft.world.level.levelgen.PositionalRandomFactory;
|
| 6 | import net.minecraft.world.level.levelgen.RandomSupport;
|
| 7 | import net.minecraft.world.level.levelgen.SingleThreadedRandomSource;
|
| 8 | import net.minecraft.world.level.levelgen.ThreadSafeLegacyRandomSource;
|
| 9 |
|
| 10 | public interface RandomSource {
|
| 11 | @Deprecated
|
| 12 | double GAUSSIAN_SPREAD_FACTOR = 2.297;
|
| 13 |
|
| 14 | static RandomSource create() {
|
| 15 | return create(RandomSupport.generateUniqueSeed());
|
| 16 | }
|
| 17 |
|
| 18 | @Deprecated
|
| 19 | static RandomSource createThreadSafe() {
|
| 20 | return new ThreadSafeLegacyRandomSource(RandomSupport.generateUniqueSeed());
|
| 21 | }
|
| 22 |
|
| 23 | static RandomSource create(final long seed) {
|
| 24 | return new LegacyRandomSource(seed);
|
| 25 | }
|
| 26 |
|
| 27 | static RandomSource createThreadLocalInstance() {
|
| 28 | return new SingleThreadedRandomSource(ThreadLocalRandom.current().nextLong());
|
| 29 | }
|
| 30 |
|
| 31 | static RandomSource createThreadLocalInstance(final long seed) {
|
| 32 | return new SingleThreadedRandomSource(seed);
|
| 33 | }
|
| 34 |
|
| 35 | RandomSource fork();
|
| 36 |
|
| 37 | PositionalRandomFactory forkPositional();
|
| 38 |
|
| 39 | void setSeed(long seed);
|
| 40 |
|
| 41 | int nextInt();
|
| 42 |
|
| 43 | int nextInt(int bound);
|
| 44 |
|
| 45 | default int nextIntBetweenInclusive(final int min, final int maxInclusive) {
|
| 46 | return this.nextInt(maxInclusive - min + 1) + min;
|
| 47 | }
|
| 48 |
|
| 49 | long nextLong();
|
| 50 |
|
| 51 | boolean nextBoolean();
|
| 52 |
|
| 53 | float nextFloat();
|
| 54 |
|
| 55 | double nextDouble();
|
| 56 |
|
| 57 | double nextGaussian();
|
| 58 |
|
| 59 | default double triangle(final double mean, final double spread) {
|
| 60 | return mean + spread * (this.nextDouble() - this.nextDouble());
|
| 61 | }
|
| 62 |
|
| 63 | default float triangle(final float mean, final float spread) {
|
| 64 | return mean + spread * (this.nextFloat() - this.nextFloat());
|
| 65 | }
|
| 66 |
|
| 67 | default void consumeCount(final int rounds) {
|
| 68 | for (int i = 0; i < rounds; i++) {
|
| 69 | this.nextInt();
|
| 70 | }
|
| 71 | }
|
| 72 |
|
| 73 | default int nextInt(final int origin, final int bound) {
|
| 74 | if (origin >= bound) {
|
| 75 | throw new IllegalArgumentException("bound - origin is non positive");
|
| 76 | } else {
|
| 77 | return origin + this.nextInt(bound - origin);
|
| 78 | }
|
| 79 | }
|
| 80 | }
|
| 81 |
|