A small invitation to stay curious, make a mess, and write down what happens.
FIELD NOTES / math
[Sample] Math, code & small explosions

A circle inside a square #
Imagine throwing points at a square from to on each axis. A point lands inside the unit circle when .
The ratio of areas gives us an estimate:
A tiny simulation #
function estimatePi(samples = 100_000) {
let inside = 0;
for (let i = 0; i < samples; i++) {
const x = Math.random() * 2 - 1;
const y = Math.random() * 2 - 1;
if (x * x + y * y <= 1) inside++;
}
return (4 * inside) / samples;
}
Read the result carefully #
More samples usually improve the estimate, but randomness does not promise a perfectly smooth journey. The typical error shrinks on the order of .1
Keep a record #
Run the function a few times with different sample counts. Note the spread, not just the result closest to the value you expected.
Follow the next question #
What would change if the points were not uniformly distributed? What would you measure to detect that? An experiment becomes useful when it creates a better question.
Footnotes #
-
This is a statistical rule of thumb for independent samples, not a guarantee for any single run. ↩

