What distribution to sample X from to get an uniform distribution in Y? 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.

I suspect the difficulty you are having is in the generation of $x$ from $f(x) \propto |\sin(x)|$.  I have coded a very simple acceptance-rejection random number generator in R that will do the job:
# Accept-reject algorithm
rsin <- function() {
  repeat {
    u <- runif(1, 0, 2*pi)
    u2 <- runif(1)
    if (u2 <= abs(sin(u))) break
  }
  u
}

Running the resultant random numbers through the cosine tranformation yields:
x <- rep(0, 10000)
for (i in seq_along(x)) {
  x[i] <- cos(rsin())
}

hist(x)


which would seem to support your derivation!
