---
# System prepended metadata

title: Monte Carlo Simulations (ABI 2022-09-08)

---

# Monte Carlo Simulations (ABI 2022-09-08)

A Monte Carlo Simulation is a method use to estimate the value of functions that work on continuous values by applying them to randomly chosen subsets of the values and extrapolating results from there.

For example, consider the following function for estimating the value of $\pi$.

```python=
import random
# Goal: approximate pi by choosing random numbers on the Q1 square (0<x<1, 0<y<1), 
# and finding which % are in the unit circle. if we take that % of 4 (the area of the unit circle),
# we should end up with an approximation of pi
rand_points = [(random.random(),random.random()) for _ in range(5000)]
passing = [(x*x+y*y) < 1 for x,y in rand_points]
percentage = len([b for b in passing if b]) / len(passing)
print(4*percentage)
```

In my testing this prints a number between ~3.05 and ~3.26


1. The `random.random()` function generates numbers uniformally within $[0,1)$. How can you use this to generate random numbers uniformally between $(-2,5)$?
2. Use a monte carlo method to approximate $\int_{0}^{3} x^2 \,dx$
3. IQ is normally distributed with a mean of 100 and a standard distribution of 15. Suppose I put 15 random people in a room. What is the chance at least 3 of them have IQ $\geq 130$?