Last active
December 15, 2015 08:19
-
-
Save sedaghatfar/5229752 to your computer and use it in GitHub Desktop.
[Python3] Monte Carlo on 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
from random import random | |
from math import pow | |
simulations = 5000 | |
hits = 0.0 | |
for x in range(simulations): | |
x = random() | |
y = random() | |
distance = pow(x,2) + pow(y,2) | |
if distance <= 1.0: | |
hits = hits + 1.0 | |
pi = (hits/simulations) * 4 | |
print(pi) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment