Function cmb_random_hyperexponential

Function Documentation

double cmb_random_hyperexponential(unsigned n, const double *ma, const double *pa)

Hyperexponential on [0, oo), choosing and samples one of n exponential distributions. Assumes that pa sums to 1.0.

The probability of selecting distribution i is p_arr[i], the mean of that distribution is ma[i]. The overall mean is the sum of pa[i] * ma[i].

Uses a simple O(n) implementation. If n is large and speed is important, consider using O(1) Vose alias sampling to select the distribution instead of this function.

See also https://en.wikipedia.org/wiki/Hyperexponential_distribution