Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- import random
- plt.xlabel('Quantity')
- plt.ylabel('Probability')
- plt.suptitle('Plot of probability')
- import time
- start_time = time.time()
- N = 5000
- cnt = 0
- x=[]
- y=[]
- seeds = [1]*60+[0]*(100-60)
- for i in range(N):
- n=0
- x.append(i)
- for _ in range(1200):
- if random.choice(seeds) == 1:
- n += 1
- if n < 739 and n > 699:
- cnt+=1
- y.append(cnt/(i+1))
- else:
- y.append(0)
- print("Answer: %a" % (cnt/N))
- plt.plot(x,y)
- plt.plot ([1, N],[0.76,0.76], 'r-')
- print("Time: %a seconds" % (time.time() - start_time))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement