SampleExp <- function(n, lambda, realization=1){ #i.i.d. sample of size n from exp(lambda). set.seed(realization); return((-1/lambda)*log(runif(n)))} v<- SampleExp(n=10^4, lambda=1)# set n=10000, lambda=1. hist(v, breaks=50, freq=FALSE, ylim=c(0, 1), xlim=c(0,8), # plot the distribution of the values produced main="n=10000, lambda=1", col="red") curve(dexp(x, rate=1), col="blue", lwd=3, add=TRUE)