User:Joabroyt/sandbox/Randomness

Randomness in Minecraft generally refers to events or outcomes which are not supposed to ever be predictable. Minecraft uses s, which means any random event is determined by an internal state that changes after every random number call, but due to the large number of possible states and a lack of human-perceptible patterns this appears as if it was truly random.

Types of randomness distributions in Minecraft
Minecraft uses different types of randomness distributions for different things. A randomness distribution describes what the odds are of picking a random value in different parts of the randomness range.

Uniform distribution
Arguably the simplest distribution to understand: once you've specified a range, you will have an equal probability of picking any value anywhere within that range. One implementation of this could look like: public double uniform(double min, double max) { return min + randomDouble * (max-min); }

Triangular distribution
A triangular distribution is where the distribution graph is shaped like a triangle: values at the center of the range are most likely to occur, while values at the edge of the range (±variance) are the least likely to occur, and the odds of any value in between is linearly distributed. The implementation of the triangular distribution in Minecraft is a. public double triangle(double center, double variance) { return center + variance * (randomDouble - randomDouble); }

Gaussian distribution
Also called a or a bell curve, the gaussian distribution has a higher probability of generating values around its center, but has a smoothed shape. A gaussian distribution has no theoretical limits for how big or small of a value it can return, but the implementation of MarsagliaPolarGaussian that is used in Minecraft has a practical limit of ±8. public double nextGaussian { double v1, v2, s;    if (this.haveNextNextGaussian) { this.haveNextNextGaussian = false; return this.nextNextGaussian; }    do { v1 = 2.0 * randomDouble - 1.0; v2 = 2.0 * randomDouble - 1.0; } while ((s = Mth.square(v1) + Mth.square(v2)) >= 1.0 || s == 0.0); double g = Math.sqrt(-2.0 * Math.log(s) / s); this.nextNextGaussian = v2 * g;    this.haveNextNextGaussian = true; return v1 * g; }