Skip to content

Instantly share code, notes, and snippets.

@elnikkis
Created July 21, 2017 04:29
Show Gist options
  • Save elnikkis/d79f8797cadf6419f79d1876286141ee to your computer and use it in GitHub Desktop.
Save elnikkis/d79f8797cadf6419f79d1876286141ee to your computer and use it in GitHub Desktop.
# coding: utf-8
import random
import math
def fall():
rad = random.random() * math.radians(360)
c = random.random() + math.fabs(math.cos(rad))
if c > 1:
return 1
else:
return 0
N = 1000000
cnt = 0
all = 0
while True:
all += N
for i in xrange(N):
cnt += fall()
print(cnt)
print(all)
print(float(cnt)/all)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment