I am tasked with randomly sampling from the following probability density function, which is a modified Erlang Function:


$$f(k,q,\nu)=\frac{(k q)^{k-1}}{[(k-1) !]^{v}} \quad \text { with } \quad q \equiv p \cdot e^{-p}$$


The ordinary Erlang function is given by


$$f(x ; k, \lambda)=\frac{\lambda^{k} x^{k-1} e^{-\lambda x}}{(k-1) !} \quad \text { for } x, \lambda \geq 0$$


Wikipedia states [here](https://en.wikipedia.org/wiki/Erlang_distribution#Generating_Erlang-distributed_random_variates) that the Erlang function may be randomly sampled according to the following function:


$$E(k, \lambda)=-\frac{1}{\lambda} \ln \prod\_{i=1}^{k} U\_{i}$$


How is this equation derived, such that I may hopefully apply the same method to this special function? If this is not applicable, for my education, how would one sample such a distribution?



Random sampling from modified Erlang distribution
$\newcommand\la\lambda$If $X\_1,X\_2,\dots$ are iid random variables (r.v.'s) each with the exponential distribution $E(\la)$ with parameter $\la$, [then](https://en.wikipedia.org/wiki/Erlang_distribution#Related_distributions)
$\sum\_1^n X\_i\sim E(k,\la)$.


In turn, if $U\_1,U\_2,\dots$ are iid r.v.'s each with the uniform distribution over the interval $(0,1)$, then the r.v.'s $X\_i:=-\dfrac1\la\,\ln U\_i$ will be iid, each with the exponential distribution $E(\la)$. So,
$$-\frac1\la\, \ln \prod\_{i=1}^k U\_i
=\sum\_{i=1}^k\Big(-\frac1\la\, \ln U\_i\Big)
=\sum\_{i=1}^k X\_i
\sim E(k,\la),$$
as desired.




---


As for your modification of the Erlang distribution, it is quite unclear how you define it. In particular, what are $p$, $v$, and $\nu$? What is the set of possible values of $k$? Is the resulting function $f$ a density function? Is there a reference to such a modification of the Erlang distribution?




---


**Details on why $\sum\_{i=1}^k X\_i\sim E(k,\la)$ if $X\_1,X\_2,\dots$ are iid random variables (r.v.'s) each with the exponential distribution $E(\la)$ with rate parameter $\la$:** This follows immediately from the following facts:


1. $E(k,\la)=\text{Gamma}(k,\la)$, where $\text{Gamma}(k,\la)$ is the gamma distribution with shape parameter $k$ and rate parameter $\la$. In particular, the exponential distribution $E(\la)$ is the same as $\text{Gamma}(1,\la)$.
2. If r.v.'s $X\sim\text{Gamma}(a,\la)$ and $Y\sim\text{Gamma}(b,\la)$ are independent, [then](https://en.wikipedia.org/wiki/Gamma_distribution#Summation)$X+Y\sim\text{Gamma}(a+b,\la)$; here $a$ and $b$ are any positive real numbers. This fact can be found in any textbook on mathematical statistics, and it can be quickly proved e.g. using the moment generating function for the gamma distribution.


