test_coin_flip_distribution.py
Go to the documentation of this file.
00001 import math
00002 import numpy as np
00003 import pylab as pb
00004 import sys
00005 
00006 
00007 #number of times until success
00008 coin_success_prob = float(sys.argv[1])
00009 counts = []
00010 for i in range(1000):
00011     success = False
00012     count = 0
00013     while not success:
00014         #flip coin, increment
00015         a = np.random.rand()
00016         if a > coin_success_prob:
00017             success = True
00018         else:
00019             count = count + 1
00020     counts.append(count)
00021 
00022 print np.mean(counts)
00023 print np.std(counts)
00024 #print counts
00025 pb.hist(counts)
00026 pb.show()
00027 


hai_sandbox
Author(s): Hai Nguyen
autogenerated on Wed Nov 27 2013 11:46:56