I wish to simulate the random variable according to pdf $$ f(x)=xe^{-x} $$ I have to feeling that I should first simulate an exponential random variable $t$ with parameter -1 and try to use the composition method, but can't seem to figure out exactly how.
Thank you in advance.
The simplest thing to do is recognize that the given density corresponds to a Gamma random variable, namely $$X \sim \operatorname{Gamma}(2, 1),$$ and therefore is the sum of two IID exponential random variables with rate parameter $1$: $$X = X_1 + X_2$$ where $X_1, X_2 \sim \operatorname{Exponential}(1)$. So a simple way to do the simulation is to generate $2n$ simulations of an exponential distribution with rate $1$, then add them in pairs to obtain $n$ simulations from $X$.