User:Joabroyt/sandbox/Randomness

Randomness is when 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.

Linear 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 linear(double min, double max) { return min + random.nextDouble * (max-min); }

Triangular distribution
A triangular distribution is where the distribution graph is shaped like a triangle: ... . The implementation of the triangular distribution in Minecraft is a. public double triangle(double center, double falloff) { return center + falloff * (this.nextDouble - this.nextDouble); }

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 * this.randomSource.nextDouble - 1.0; v2 = 2.0 * this.randomSource.nextDouble - 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; }