# we can simulate two dice -- die 1 and die2 # and look at the distribution of their sum # either as a table of frequencies or a histogram die1 = sample(1:6, 100, replace=TRUE) die2 = sample(1:6, 100, replace=TRUE) sum = die1 + die2 sum table(sum) hist(sum, breaks=1.5:12.5) # we can simulate three dice -- die 1, die2 and die3 # and look at the distribution of their sum # either as a table of frequencies or a histogram die1 = sample(1:6, 100, replace=TRUE) die2 = sample(1:6, 100, replace=TRUE) die3 = sample(1:6, 100, replace=TRUE) sum = die1 + die2 + die3 sum table(sum) hist(sum, breaks=2.5:18.5, main="Three dice simulation", xlab="sum of three dice", ylab="Frequency (100 total)", col="blue") # we can simulate three dice -- die 1, die2 and die3 # and look at the distribution of their sum # either as a table of frequencies or a histogram die1 = sample(1:6, 1000, replace=TRUE) die2 = sample(1:6, 1000, replace=TRUE) die3 = sample(1:6, 1000, replace=TRUE) die4 = sample(1:6, 1000, replace=TRUE) sum = die1 + die2 + die3+die4 table(sum) hist(sum, breaks=3.5:24.5, main="Four dice simulation", xlab="sum of four dice", ylab="Frequency (1000 total)", col="green")