Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. import random
  3.  
  4. plt.xlabel('Quantity')
  5. plt.ylabel('Probability')
  6. plt.suptitle('Plot of probability')
  7.  
  8. import time
  9. start_time = time.time()
  10.  
  11. N = 5000
  12. cnt = 0
  13.  
  14. x=[]
  15. y=[]
  16.  
  17.  
  18. seeds = [1]*60+[0]*(100-60)
  19. for i in range(N):
  20. n=0
  21. x.append(i)
  22. for _ in range(1200):
  23. if random.choice(seeds) == 1:
  24. n += 1
  25. if n < 739 and n > 699:
  26. cnt+=1
  27. y.append(cnt/(i+1))
  28. else:
  29. y.append(0)
  30.  
  31.  
  32.  
  33.  
  34. print("Answer: %a" % (cnt/N))
  35.  
  36. plt.plot(x,y)
  37.  
  38. plt.plot ([1, N],[0.76,0.76], 'r-')
  39.  
  40. print("Time: %a seconds" % (time.time() - start_time))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement