Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I am allowed to make any number of coin tosses. Coin is unbiased. How can I generate a given random variable X (say X is bernouille or binomial or uniform) using independent coin tosses. I am looking at this direction. Given X a random variable, I have to conduct an m coin tosses experiment for some m such that we associate X=i to some event say E_i in the experiment such that probability of occurrence of the event E_i is same as that of p(X=i) for each possible value i that X takes.

Can you help me how to generate random variable say bernouille (p)/binomial (n,p) at least using coin tosses.

Thanks,

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

I assume that you want to generate an artificial sample of the random variable $X$. If you want a general method, you might use the inverse transform sampling: use your coin to generate a random number between $0$ and $1$ (for instance, count tails as 1s and heads as 0s and generate a binary number .11101001... to the desired accuracy), and then evaluate the quantile function (which is more or less the inverse of the cumulative distribution function) on this number.

For each concrete distribution there may be more effective methods, of course. But the above procedure is simple enough in the case of the Bernoulli distribution: toss your coin until you know whether the binary number .11101001... is greater or less than $1-p$ ($p$ being the probability of success). If it is less than $1-p$, count that as a failure. If it is greater than $1-p,$ count it as a success.

share|improve this answer
    
Thanks for your answer. –  TheNeo Apr 19 '12 at 8:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.