From Discrete-Event System Simulation
\[ F(x) = \begin{cases} 0, x \le -3 \\ \frac{1}{2} + \frac{x}{6}, -3 \le x \le 0 \\ \frac{1}{2} + \frac{x^2}{32}, 0 \lt x \le 4 \\ 1, x \gt 4 \end{cases} \]
The range is defined from -3 to 4 so we’ll focus specifically on \(-3 \le x \le 4\).
\[F(x) = \frac{1}{2} + \frac{X}{6} = R\]
Solving for R:
\[ \frac{X}{6} = R - \frac{1}{2} \] \[ X = 6(R - \frac{1}{2}) \]
Using equation \(\frac{1}{2} + \frac{x}{6}\) and using \(-3 \le X \le 0\) we define the range to b:
\[ 0 \le R \le \frac{1}{2} \]
\[F(x) = \frac{1}{2} + \frac{X^2}{32} = R\]
Solving for R:
\[ \frac{X^2}{32} = R - \frac{1}{2} \] \[ X^2 = 32(R - \frac{1}{2}) \] \[ X= \sqrt{32(R - \frac{1}{2})}\]
Using equation \(\frac{1}{2} + \frac{x^2}{32}\) and using \(0 \le X \le 4\) we define the range to be:
\[ \frac{1}{2} \le R \le 1 \]
\[ X = \begin{cases} 6(R - \frac{1}{2}), 0 \le R \le \frac{1}{2} \\ \sqrt{32(R - \frac{1}{2}}, \frac{1}{2} \le R \le 1 \\ \end{cases} \]
generator <- function(R) {
return( ifelse(R <= 1/2, 6*(R - 1/2), sqrt(32*(R - 1/2))))
}
# apply to 1000 samples between 0 and 1
result <- sapply(runif(1000), generator)
head(result, 10)
## [1] -1.2745349 3.0373943 -0.5461385 3.5009366 3.7543246 -2.7266610
## [7] 0.9483542 3.5436435 1.2829343 -0.2603116
hist(result)