I'm trying to create a random number generator on the interval $(a,c)$ given a probability density function defined as: $$f(x) = \left\{ \begin{array}{lr} \dfrac{C}{x} &, x \in (a,b)\\ \dfrac{\gamma C}{x} &, x \in (b,c) \end{array} \right. $$ Where $C$ is a normalization constant given by $$ \int^b_a\frac{C}{x}dx+\int^c_b\frac{\gamma C}{x}dx=1 $$ I know that I'm supposed to use the inverse transform method to find the random number $y$ given a uniformly generated random number $u(0,1)$.
I obtain the following two expressions for $y$: $$ y=\exp\left(\frac{u(0,1)}{C}+\ln{a}\right) $$ and $$ y=\exp\left(\frac{u(0,1)}{\gamma C}+\ln{b}\right) $$ However, I'm not sure how to select between the two depending on the value of $u(0,1)$ and I'm getting numbers outside the interval $(a,c)$.
Any help would be appreciated.
$\ln$
. $\endgroup$ – user153918 Apr 29 '15 at 17:19