Assume I have a random integer in the range form 0 to 7 and I want to generate a random integer from 0 to 9, how would I go about doing so?
I though about doing the following: First I choose a random number from 0 to 7. Then I reduce this number mod 2. Then I can choose one of the sets $\{0,...4\}$ and $\{5,...,9\}$, so the problem is reduced to choosing a random number from 0 to 4. Now one can choose random numbers from 0 to 7 until one lies between 0 an 4.
Unfortunately the above method does not necessarily terminate(although it terminates with prbability 1), so I was wondering about a method that guarantees me to terminate after a finite numer of steps.
Also I was wondering more generally if there is a strategy to transform a random variable that is equally distributed between $0$ and $n$ into a random variable that is equally distributed between $0$ and $m$. I think one can extend the above strategy to reduce the problem to find a random variable equally distributed between $0$ and $(m+1)/gcd(n+1,m+1)-1$ but in generally(for example if $n+1$ and $m+1$ are both prime) this is not really helpfull.
When $|Y|$ has prime factors that aren't prime factors of $|X|$ you can't transform a uniform distribution on $X$ to a uniform distribution of $Y$.
It's a simple fact that many people doesn't realise.
The simplest case, that I have succesfully used to convince people (unfortunately not all) is: Imagine that you have to decide if your new car should be red, green or blue and all you have is a coin - no matter what strategy (that gives an equal distribution) you use for mapping the result of a series of coin flips there will always be a chance that you flip a sequence that doesn't map to any of the choices.