How could random variables with the following density function be generated from a uniform random number generator? $f (x) = \frac{1 + \alpha x}{2}$, $ −1 ≤ x ≤ 1$, $−1 ≤\alpha ≤ 1$.
To find the Random number generator one first needs to find the distribution function and then the quantile function. However, I have troubles solving this on my own:
\begin{align} F(x) & = \int_{-1}^x \frac{1+\alpha u}{2} du\\ & = \frac 12 \Big( (x+\frac{\alpha x^2}{2})-(-1+\frac{\alpha}{2})\Big)\\ & = \alpha x^2 + 2x + 2 - \alpha \end{align}
I am not sure how to handle the $\alpha$. For getting the quantile(=inverse) function i need to solve this last expression for x.
Not sure how you get from your second line to the third, there is clearly error somewhere
\begin{equation} F(x) = \frac{\alpha}{4}(x^2 - 1) + \frac{1}{2}(x+1) \end{equation}
with obvious properties $F(x=-1)=0$ and $F(x=1)=1$. Now assign $F(x)$ to RV $\xi$ in the [0...1] range and find inverse:
\begin{equation} x = F^{-1}(\xi) \end{equation}
Simple quadratic equation with solution:
\begin{equation} x = \frac{2 \; \sqrt{\frac{1}{4} + \alpha(\frac{\alpha}{4} + \xi - \frac{1}{2})} - 1}{\alpha} \end{equation}
For the case when $\alpha=0$, $x=2\xi-1$
Easy to check:
\begin{equation} \xi=0, \;then\; x=-1 \end{equation} \begin{equation} \xi=1, \;then\; x=+1 \end{equation}
Python code
generates graphs like one below for sampled vs PDF