Simulation - Composition method

Hi all, this question doesn't really have to do with C, but it is related to simulation, and without solving this first, I can't do the random variate generator.

I'm supposed to generate random variates for p(x) ~ pi - x + x^2 + sin(x), for 0 <= x <= pi.

I got the normalization factor as 6 / (12 + 3*pi^2 + 2*pi^3), which gives me my f(x) as

f(x) = [6 / (12 + 3*pi^2 + 2*pi^3)] * (pi - x + x^2 + sin(x)).

I then run into problems decomposing the f(x). I decomposed it into the following equation:

f(x) = 6*pi / a - (3*pi^2 / a) * f_1(x) + (2*pi^3 / a) * f_2(x) + (12 / a) * f_3(x)

where a = (12 + 3*pi^2 + 2*pi^3), f_1(x) = 2x/pi^2, f_2(x) = 3x^2 / pi^3, f_3(x) = ½ sinx.

I reasoned that f_1 is proportional to x, f_2 to x^2, and f_3 to sin(x). I then normalized f_1, f_2 and f_3, obtaining the respective individual distributions.

However, I'm confused by the presence of the constant term 6*pi / a and the negative sign in front of f_1. What should I do with them?

I'm really confused with the whole composition method, and I would greatly appreciate it if someone could point me to a website that gives a clear explanation of how to decompose the distributions.

Thank you.

Regards,

Rayne