Skip to content

Instantly share code, notes, and snippets.

@seungha-kim
Created January 29, 2015 05:35
Show Gist options
  • Save seungha-kim/20d76b251b0d3cabdee1 to your computer and use it in GitHub Desktop.
Save seungha-kim/20d76b251b0d3cabdee1 to your computer and use it in GitHub Desktop.
# Monte Carlo method
# http://en.wikipedia.org/wiki/Monte_Carlo_method
from random import random as rnd
from math import sqrt
trial = 1000000
hit = 0
for i in range(trial):
if sqrt(rnd()**2 + rnd()**2) < 1:
hit += 1
print 1.0*hit/trial*4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment