2.6 A Monte Carlo Simulation
Our final technique for approximating pi will make use of probability and random behavior. These types of solutions are often referred to as Monte Carlo simulations because they use features that are similar to “games of chance.” In other words, instead of knowing specifically what will happen during the simulation, a random element is introduced into the simulation so that it will behave differently each time.
To set up our simulation, consider FIGURE 2.9. Pretend that we are looking at a dartboard in the shape of a square that is 2 units wide and 2 units high. A circle has been inscribed within the square so that the radius of the circle is 1 unit.
Now assume ...
Get Python Programming in Context, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.