Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. d <- 8 # Sides of the die
  2. throws <- 20 # Number of throws
  3. no_cut <- 6 # Number at least on die
  4. n_lower <- 12 # Lower cutoff
  5. n_upper <- 16 # Upper cutoff
  6.  
  7. n_sim <- 1000000 # Number of simulations
  8.  
  9. res <- NULL
  10.  
  11. res <- replicate(n_sim, {
  12. x <- sample.int(d, size = throws, replace = TRUE)
  13. s <- sum(x > no_cut)
  14. (s >= n_lower && s <= n_upper)
  15. })
  16.  
  17. sum(res)/n_sim # simulated probability
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement