Say I have a coin, aka 1d2, aka a 2-sided die. I need to get a random integer from 1 to n with equal probability of all n integers. I can flip/roll my coin/1d2 as many times as I need to (within reason/practicality).
How can I use a coin/1d2 to get, say, an evenly/linearly distributed random number from 1 to 6?
My initial approach is to simply roll 6 times and add up the number of times I get heads/1, and ignore any tails/2 values. But over multiple iterations this yields a (gaussian?) distribution matching a bell curve; 3 is most likely, followed by 2 and 4, then 1 and 5, and least likely 0 and 6 (which is another problem; the result can be 0).
I'll accept something that's a close approximation to equal probability, provided the procedure works for multiple values of n and not just 6.
There are lots of ways to do this, some less efficient than others. Powers of $2$ are easy, because for $1$ to $4$, for example, you can assign $1,1\to 1$; $1,2\to2$; $2,1\to3$; and $2,2\to4$. If you wanted to do $1$ to $3$, you can use the same method, but let $2,2$ map to "start over." Generalize this idea to $n$.