rationalities

Testing Exploding Dice Expected Value

Sep 19th, 2020
158
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. set.seed(123)
  2.  
  3. N    = 6           #set sides of dice
  4. Nsim = 10000000    #set number of simulations
  5. vals = rep(0,Nsim) #initialize simulation vector
  6.  
  7. for(i in 1:Nsim){
  8.  
  9.   draw = sample(1:N,1) #draw value
  10.   val  = draw          #set value
  11.  
  12.   #start recursive loop
  13.   #if draw == N, draw again and add to val
  14.   #keep doing while draw == N
  15.  
  16.   while(draw == N){
  17.     draw = sample(1:N,1)
  18.     val  = val + draw
  19.   }
  20.   vals[i] = val
  21. }
  22.  
  23. mean(vals)          #simulated expected value
  24. (N/2)*((N+1)/(N-1)) #theoretical expected value
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×