I have a random variable $X$ which is related to another random variable $Y$ as $Y = \text{cos}(X)$, where $X \in [0, \pi/2]$, and I would like to know what distribution I should sample $X$ from in order that $Y$ has a uniform distribution. A simple Jacobian transformation says that
$f(Y) = |\frac{\partial X}{\partial Y}| f(X)$
which suggest that in order to have $f(Y) = 1$ (i.e. uniform), we should equate $f(X) = |\frac{\partial Y}{\partial X}| $. In this specific example that would mean we need to sample $x$ from the distribution $f(X) = |\text{sin(X)}|$.
However when I do this in practice i.e. I plug a sample of $x$ values drawn from a sine distribution into the cosine, the resulting distribution of $y$ values is not uniform at all, but rather looks like this.
Could someone please point out what I am doing wrong?
Thanks in advance.