Skip to content

Instantly share code, notes, and snippets.

@sedaghatfar
Last active December 15, 2015 08:19
Show Gist options
  • Save sedaghatfar/5229752 to your computer and use it in GitHub Desktop.
Save sedaghatfar/5229752 to your computer and use it in GitHub Desktop.
[Python3] Monte Carlo on Pi
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