Generate random number with specific probability distribution Well consider I have a uniform random number generator. How would I craft a function which takes as parameter this RNG, such that the distribution is following a given function?
Or more to the point: I have a a function $f(x) = 0.75-0.75x^2$ (and outside the interval $[-1, 1]$ it is $0$. This function represents the distribution I wish to gain. 
Now as the integral represents the chance a number is between two boundaries, I could integrate above function between $[-1, X]$ and this value would then represent the "RNG(x)". Doing so:
$$\int_{-1}^X 0.75 -0.75x^2 dx = 2 \cdot \mathrm{RNG}(x) - 0.5$$
$\mathrm{RNG}(X)$ gives a number between $[0, 1]$ so I convert it also to the correct 
$$-0.25X^3 + 0.75X - 0.5 = 2 \cdot \mathrm{RNG}(x) - 0.5$$
However this is an unsolvable equation? How would I make a RNG with said distribution?

What about an approximation:


*

*draw $N$ random numbers from intervall $[-1,1]$

*calculate probability of each number with your $f\left(x\right)$

*draw one on the number with probability propotional to your calculated probability.


example matlab/octave code:
allVals = zeros(1,10000);
for i = 1: 10000;
    % draw n numbers
    vals = rand(1,1000)*2-1;
    % calculate probability of each
    prob = 0.75 - 0.75.*vals.^2;
    % select proportoinal to probability
    idx = find(rand(1)*sum(prob) < cumsum(prob),1);
    allVals(i) = vals(idx);
end

figure(1);
clf();
plot(-1:0.01:1,0.75-0.75*(-1:0.01:1).^2,'b-')
figure(2);
clf();
hist(allVals,50);

