This is a simple stochastic model to determine the value of pi.
Imagine people are throwing darts at a dartboard fitted inside a square frame. All the darts land somewhere inside the frame, some on the board, some out.
All the darts land inside the frame at random: the proportion of darts inside the circular dartboard will be the area of the circle (pi r^2 ) / d^2 (area of the frame). Since d = 2r, we can use the randomly generated dart throws to calculate pi.
This is done by considering 1 X 1 (any units) square frame, into which a quarter circle fits (our frame area is divided by 4) and generating the X and Y coordinates of the dart hit randomly.
We then test if the throw hits inside the quarter circle; for that to happen, the hypotenuse must be <= 1. We use Pythagoras' theorem to calculate the value for the hypotenuse based on the X and Y values.
The number of time steps is the number of times the dart is thrown, and a factor of 4 is used to convert the quarter circle into the real thing.
Because this is a stochastic model, every run gives a different-shaped curve (you need to close the graph display every time and re-run).
But why don't we start the model at zero?