Guest User

Untitled

a guest
Dec 15th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. > m = 10^6; die = 1:6
  2. > s = replicate( m, sum(sample(die, 3, rep=T)) )
  3. > round(table(s)/m, 3)
  4. s
  5. 3 4 5 6 7 8 9 10
  6. 0.005 0.014 0.028 0.046 0.069 0.097 0.116 0.125
  7. 11 12 13 14 15 16 17 18
  8. 0.125 0.116 0.097 0.069 0.046 0.028 0.014 0.005
  9.  
  10. > m = 10^6; pop = 1:365; n= 25
  11. > match = replicate(m, n - length(unique(sample(pop, n, rep=T))) )
  12. > mean(match); mean(match==0)
  13. [1] 0.806556
  14. [1] 0.430406
  15.  
  16. m = 10^6; pop = 1:365; n = 25; match=numeric(m)
  17. for (i in 1:m) {
  18. bdays = sample(pop, n, rep=T)
  19. u = unique(bdays); nu = length(u)
  20. match[i] = n - nu }
  21. mean(match)
  22. ## 0.805725
  23. mean(match==0)
  24. ## 0.430961
Add Comment
Please, Sign In to add comment