library(openintro)
data(COL)

Promotion rates

N<-10000
candidates<-c(rep(T,35),rep(F,13))
differences<-rep(0,N)
for (i in 1:N){
  m<-sum(sample(candidates,24))
  f<-sum(c(rep(T,35-m),rep(F,13-24+m)))
  differences[i]<-m/24-f/24
}
hist(differences,freq=FALSE,col=COL[1,2],xlab="Difference in promotion rates",main='')

Distributions of a single six sided die

#Generate a uniform random distribution from min to max
numcases <- 10000                           #how many cases to generate

min <- 1                                  #set parameters
max <- 6

x<-sample(min:max,numcases,replace=TRUE) #generate random uniform numcases numbers from min to max

par(mfrow=c(2,1))                        #stack two figures above each other

hist(x,main=paste( numcases," roles of a single die"),breaks=seq(min-.5,max+.5,1))          #show the histogram
boxplot(x, horizontal=TRUE,range=1)              # and the boxplot
title("boxplot of a uniform random distribution")

Simulation of two six-sided dice

#generate a uniform random distribution from min to max for numcases samples of size 2
numcases <- 10000                            #how many cases to generate
min <- 1                                    #set parameters
max <- 6
x <- sample(min:max,numcases,replace=TRUE)+sample(min:max,numcases,replace=TRUE)
par(mfrow=c(2,1))                        #stack two figures above each other
hist(x,breaks=seq(1.5,12.5),main=paste( numcases," roles of a pair of dice"))          #show the histogram                                 
boxplot(x, horizontal=TRUE,range=1)      # and the boxplot
title("boxplot of samples of size two taken from a uniform random distribution")

Simulation of 32 six-sided dice

#generate a uniform random distribution from min to max for numcases samples of size 2
numcases <- 10000                            #how many cases to generate
min <- 1                                    #set parameters
max <- 6
x<-rep(1,numcases)
for(i in 1:32){
    x <- x+sample(min:max,numcases,replace=TRUE)
}
par(mfrow=c(2,1))                        #stack two figures above each other
hist(x,breaks=seq(32*min-.5,32*max+.5,1),main=paste( numcases," roles of thirty two dice"),col=COL[1,4])          #show the histogram 
abline(v=32*3.5,col=COL[4,1])
boxplot(x, horizontal=TRUE,range=1)      # and the boxplot
title("boxplot of samples of size thirty two taken from a uniform random distribution")