Advertisement
iSach

Random prob test with dice

Apr 11th, 2019
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. import random
  2.  
  3. n = 3
  4. number = 2
  5. amount = 2
  6. n_simulations = 100000
  7. success = 0
  8.  
  9. def check(vector, num, amount):
  10. count = 0
  11. for i in range(len(vector)):
  12. if vector[i] is num:
  13. count += 1
  14. if count >= amount:
  15. return 1
  16. return 0
  17.  
  18.  
  19. for i in range(n_simulations):
  20. vect = [0] * n
  21. for j in range(n):
  22. vect[j] = random.randint(1, 6)
  23.  
  24. if check(vect, number, amount) is 1:
  25. success += 1
  26.  
  27. print('Result: ' + str(success / n_simulations * 100) + '%')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement