Following your suggestions I decided to use the inverse CDF method (more simple).
I know that the hazard rates are constant in the time-intervals
$$
\lambda(t) = \begin{cases} \lambda_1, & \mbox{if } 0<t\leq t_1 \\ \lambda_2, & \mbox{if } t_1<t\leq t_2 \\ \vdots & \vdots\\ \lambda_J, & \mbox{if } t_{J-1}<t\leq t_J \end{cases}
$$
that the cumulative hazard function is given by
$$
\Lambda(t) = \begin{cases} \lambda_1 t, & \mbox{if } 0<t\leq t_1 \\ \lambda_1 t_1+\lambda_2(t-t_1), & \mbox{if } t_1<t\leq t_2 \\ \vdots & \vdots\\ \sum_{i=1}^{J-1}\lambda_i(t_i-t_{i-1})+\lambda_J(t-t_{J-1}), & \mbox{if } t_{J-1}<t\leq t_J \end{cases}
$$
and that the cumulative density function is given by $F(t)=1-e^{-\Lambda(t)}$.
So generating $u\sim U(0,1)$ (simulation of the CDF value) it is possible to obtain a number ($t$) which follows a piecewise exponential distribution. More in details, it is possible to use the inverse of the cumulative hazard function (as follows), calculating $x=-\ln(1-u)$,
$$
t=\Lambda^{-1}(x) = \begin{cases} \frac{x}{\lambda_1}, & \mbox{if } 0<x\leq \lambda_1t_1 \\ t_1+\frac{x-\lambda_1 t_1}{\lambda_2}, & \mbox{if } \lambda_1t_1<x\leq \lambda_1t_1+\lambda_2(t_2-t_1) \\ \vdots & \vdots\\ t_{J-1}+\frac{x-\sum_{i=1}^{J-1}\lambda_i(t_i-t_{i-1})}{\lambda_J}, & \mbox{if } \sum_{i=1}^{J-1}\lambda_i(t_i-t_{i-1})<x\leq \sum_{i=1}^{J}\lambda_i(t_i-t_{i-1}) \end{cases}
$$
The only thing is missing is how to treat values of $x>\sum_{i=1}^{J}\lambda_i(t_i-t_{i-1})$.
Do you agree that this procedure to generate random number (piecewise exponentially distributed) is better?