dice.sum <- function(n.dice){
  dice <- sample(1:6, size = n.dice, replace = TRUE)
  return(sum(dice))
}

隨機骰1000次

dice <- replicate(1000, dice.sum(3))

三個骰子的各種可能

dice.dice <- data.frame(table(dice))
dice.dice$dice
##  [1] 3  4  5  6  7  8  9  10 11 12 13 14 15 16 17 18
## Levels: 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
plot(prop.table(table(dice)),ylab = 'Probability', main = '1000 Rolls of Three Dice')

三個骰子可能總和可能呈常態分佈。(中央極限定理)

The end