# rolling some die
d <- sample(6, 10000, replace = TRUE)
hist(d)

# mean value
mean(1:6)
mean(d)

# flipping coins
numHeads <- sapply(1:1e5, 
                   function(x) {
                     #print(x)
                     c <- sample(2, 100, replace=TRUE)
                     sum(c == 1)
                   })
#View(numHeads)
hist(numHeads, breaks=100, xlim=c(0,100))

# note - that is called a bernoulli distribution
numHeads <- sapply(1:1e6, 
                   function(x) {
                     rbinom(n=1, size=100, prob=0.5)
                   })
#View(numHeads)
hist(numHeads, breaks=100, xlim=c(0,100))

pbinom(q=30,size=100, prob=0.5)