Taming Randomness

Sketching with Math and Quasi Physics

There is a newer and more elaborate version of this site.
Visit Sketching with Math and Quasi Physics on Notion.

Uniform Random

let v = random(1)

Random2

let v = pow(random(1), 2)

Randomn

let v = pow(random(1), n)

(Random + Random) / 2

let v = (random(1) + random(1)) / 2;

(Random1 + Random2 + ... + Randomn) / n

let v = 0;
for (let i = 0; i < n; i ++) {
  v += random(1);
}
v /= n;

Normal Distribution(Gaussian)

// Box-Muller Transform (Unif(0,1) => N(0,1))
// avoiding log(0) by using (1 - random(1))
let mean = 0.5, variance = 0.1;
let v = sqrt(-2 * log(1 - random(1))) * cos(2 * Math.PI * Math.random(1)) * variance + mean;

note: randomGaussian() is available in p5.js

Perin Noise

Distribution

let v = noise(x); x += 0.001;

see implementation of noise() function in p5.js

Variation over time

let v = noise(x); x += 0.01;

Random Walkers

index