I am trying to generate exponentially distributed random number with mean equal to 1. I know how to get random number for normal distribution with mean and standard deviation. We can get it by normal(mean, standard_deviation)
, but I don't know how to get random number for exponential distribution.
Can anyone help me with this?
Generating an exponential distribution random variable can be done by:
More information can be found in this wikipedia article
In exponential distribution:
lamda = 1/mean
, so it gets you:With C++11 the standard actually guarantees that there is a RNG following the requirements of exponential-distribution available in the STL, and fittingly the object-type has a very descriptive name.
The mean in an exponentially distributed random generator is calculated by the formula
E[X] = 1 / lambda
1.std::exponential_distribution
has a constructor taking lambda as an argument, so we can easily create an object following your rules by calculating the value of lambda and passing this to our generator.Footnotes
1. according to en.wikipedia.org - Exponential distribution > Mean, variance, moments and median
Distribution as readable ascii chart