I would like to generate some pseudorandom numbers and up until now I’ve been very content with the .Net library’s Random.Next(int min, int max) function. PRNGs of this variety are supposed to be using a Uniform distribution, but I would very much like to generate some numbers using an Exponential Distribution.
I’m programming in C#, although I’ll accept pseudocode or C++, Java or the like.
Any suggestions / code snippets / algorithms / thoughts?
Since you have access to a uniform random number generator, generating a random number distributed with other distribution whose CDF you know is easy using the inversion method.
So, generate a uniform random number
uin[0,1)range, then calculatexby:x = log(1-u)/(-λ)x = log(1-uniformRand(0, 1))/(-λ)where
λis the rate parameter of the exponential distribution. Now,xis a random number with an exponential distribution. Note thatlogabove isln, the natural logarithm.