set.seed(2022)
simu_times = 10000 ## repeat the program 10000 times
res = rep(NA,simu_times) ### record the results
for ( i in 1:simu_times){
samples <- sample(1:100) #### shuffer the cards
res[i] <- sum(samples==seq(1,100,1)) ###count the number of hits
}
print(paste0(“The expectation of the total number of hits is “, mean(res)))
print(paste0(“The variance of the total number of hits is “, var(res)))
For any question, please feel free to contact me.
