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 and no defined range. public double nextGaussian { double e;    double d;     double f;     if (this.haveNextNextGaussian) { this.haveNextNextGaussian = false; return this.nextNextGaussian; }    do { d = 2.0 * this.randomSource.nextDouble - 1.0; e = 2.0 * this.randomSource.nextDouble - 1.0; } while ((f = Mth.square(d) + Mth.square(e)) >= 1.0 || f == 0.0); double g = Math.sqrt(-2.0 * Math.log(f) / f); this.nextNextGaussian = e * g;    this.haveNextNextGaussian = true; return d * g; }