Create a gist now

Instantly share code, notes, and snippets.

import random
import math
def gcd(a, b):
while b:
a, b = b, a % b
return a
count_coprime = 0
count_all = 0
while(1):
count_all += 1
a = random.randint(1,100000000)
b = random.randint(1,100000000)
if(gcd(a,b) ==1 ):
count_coprime += 1
prob = 1.0 * count_coprime / count_all
if prob >0 and count_all %10000 ==0:
pi = math.sqrt(1/(prob/6))
print pi,count_all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment