Monte Carlo Simulation For Finding Pi
Monte Carlo Simulation For Finding Pi
Monte Carlo Simulation For Finding Pi
August 2, 2021
1.1 Code
[1]: import numpy as np
import matplotlib.pyplot as plt
import random
from datetime import datetime
x = random.random()
y = random.random()
if(x*x+y*y <= 1):
circ = circ + 1
sqr = sqr + 1
else:
sqr = sqr + 1
pi_val = 4*float(circ)/float(sqr)
return pi_val
1
Enter the number of iterations : 10000
3.1496