Assume that the random variable $X$ may take $n$ values, say $P(X=k)=p_k$ for every integer $1\leqslant k\leqslant n$, with each $p_k\gt0$ and $\sum\limits_{k=1}^np_k=1$. Choose $q\gt0$ such that $p_k\geqslant q$ for every $k$ and consider the following algorithm.
Draw $X$, say the value you obtain is $k$. Draw $U$ uniform on $[0,1]$, say the value you obtain is $u$.
- If $p_ku\leqslant q$, declare that $Y=k$ and that you won.
- Otherwise, throw away $k$ and $u$ and start over with some new values of $X$ and $U$.
Continue until you are able to declare that you won.
The probability that a given step yields $Y$ is $nq$ hence the number of steps necessary to produce a value $Y$ is almost surely finite and geometrically distributed with mean $1/(nq)$. The result of this algorithm is a random value $Y$ such that $\mathrm P(Y=k)=1/n$ for every integer $1\leqslant k\leqslant n$.
Edit Let me add a reason why a randomized procedure is necessary here. Imagine to simplify things that $X$ takes two values, with $\mathrm P(X=1)=\frac13$ and $\mathrm P(X=2)=\frac23$. Thus, one starts from the histogram with two columns, one twice higher than the other, and one wants to reach the histogram with two columns of equal heights.
There is no way to decide that if $X=1$, then $Y=$ something and if $X=2$ then $Y=$ something else, which can produce equal probabilities. Roughly speaking, one must add a random choice to split the column $2$ of the histogram of $X$ into two parts with adequate heights. This is what the rejection algorithm explained above does.
In the present case, one would draw several copies of $X$ and keep all the copies equal to $1$ and roughly half of the copies equal to $2$. Thus, starting from $3n$ copies of the random variable $X$ which has uneven weights, one produces roughly $2n$ copies of the random variable $Y$ which has even weights.