nrep <- 100000 out <- rep(0,nrep) for (i in 1:nrep) { s <- 0 n <- 0 while (s<=1) { n <- n+1 x <- runif(1) s <- s+x } out[i] <- n } table(out) xm <- mean(out) xm se <- sqrt(var(out)/nrep) cil <- xm - 1.96*se cih <- xm + 1.96*se cat(xm,cil,cih,(cih-cil),"\n")