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.



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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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