Function: rexpo(s0)

rexpo <- function(s0){
     x <- runif(n = 1,min = 0,max = 1)
     y <- -s0 * log(x)
     y
}

This function generates a random number with exponential distribution (at rate = 1/s0).

PDF from rexpo(s0)

set.seed(1234)

We set s0=5. (which means rate=0.2), and generate the random numbers from the rexpo(s0).

PDF from rexp()

hist(x = rexp(n = n, rate = 1./s0), freq = 0)

rexp() is a built-in function in R for generating random numbers with exponential distribution. We generates random numbers with rate=0.2 to compare with our code. Our code gives approximately the same result.