Chapter 9 Question 10

Find the probability that among 10,000 random digits the digit 3 appears not more than 931 times.

n<-100000
digits<-rep(NA, n)

for(i in 1:n){
  temp<-sample(c(0:9),10000, replace=TRUE)
  count<-length(temp[temp==3])
  digits[i]<-count
}

#histogram
hist(digits)

#probability
length(digits[digits<=931])/length(digits)
## [1] 0.01089
#standard deviation
sd(digits)
## [1] 30.03846