This video follows a previous one in we introduced the sample() method from R programming to simulate the rolling a die. Here we extend the result to simulate the rolling of multiple dice. The line of code die1=sample(1:6, 100, replace=TRUE) generated a vector of size 100 with pseudo-random numbers drawn from the integers 1 through 6 (inclusive) and duplications allowed. In the first script considered here, two such vectors were generated and then summed. That represents rolling two dice and considering the sum of the die values. We used the hist() method to create a histogram from the result. We used the arguments breaks=1.5:12.5 because the possible sums range from 2 to 12, so our breaks extend a little below and a little above that range. We also added the col argument which change the fill color of the histogram columns. Our second script simulated the rolling of three dice.
Ещё видео!