Last active
June 9, 2017 06:57
-
-
Save Kaundur/93926be2cb9ab755bed2a4ac9522eb6a to your computer and use it in GitHub Desktop.
Monte Carlo estimation of pi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import random | |
count = 0 | |
n = 100000 | |
for i in range(n): | |
x_pos = random.uniform(0, 1) | |
y_pos = random.uniform(0, 1) | |
if x_pos**2 + y_pos**2 <= 1.0: | |
count += 1 | |
print 4*float(count)/float(n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment