I have a question in which I need to generate random numbers in the range 0-9 by means of an unbiased coin such that it is equally likely to get any number. Since there is no limit on the number of coin tosses I first tried to do it like this:
- Do 10 coin tosses.
- If a head appears in the nth coin toss, then generate that number. I.e if the sequence is 0000000001, then generate 0, if 0000000010 then generate 1 and so on. I defined this as my random variable
This method does give an equal probability of (1/2) ^ 10 but the sum of all 10 events does (while calculating the probability mass function) not sum up to one.
Then afterwards I tried to do it by defining the random variable as the appearance of consecutive heads. So if, consecutive heads = 1, then generate 0, if consecutive heads = 2, then generate the number 2 and so on. This maps to a binomial distribution, and even though it sums up to 1, the probability of getting each number is different.
Is there any way I could do this, or could anyone please give me a hint on how to approach this problem?