How to generate samples from a distribution with jump points? I'm trying to simulate a survival dataset, with the censoring variable $X$ following a continuous distribution with mass points. The distribution is
$$f(x) = \begin{cases}
\lambda_1e^{-\lambda_1x}, & 0 \le x \leq a \\
\lambda_2e^{-\lambda_2x}, & a < x \le b \\
\ \text{const}. & x > b
\end{cases}$$
How to sample from such a distribution with $R$?
 A: For your case it seems simplest to use inverse transform sampling.
Then you need to express the quantile function. For your case this requires I integrating your pdf which will be a piecewice exponential function and linear function. Then inverting this, which will be some function with logarithms.
$$F(x) = \begin{cases}
0 & x<0\\
c_1-e^{-\lambda_1x}, & 0 \le x \leq a \\
c_2-e^{-\lambda_2x}, & a < x \le b \\
c_3+x*const& b< x \le c_4 \\
1 & x> c_4
\end{cases}$$
You will need to figure out those constants $c_i$ by setting the cases equal at the boundaries. E.g. for the last case $c_3 + x*const =1$ if $x=c_4$.
A: Just treat it as a conditional distribution. So sample $x$ according to its distribution, then nest a for loop for the appropriate bounds and append to a df.
df <- vector()

x = rdist(coefficients = [coef], size = 1)
n = int(size of trials)
count = 0

while (count < n){
    if ( x > 0 & x<= a){
        df = append(df, rpois(1,lamda1*x)
    }

### repeat for the other bounds on x ###

    count++
)

print(df)

