Sum of random coin flips

Let x be a variable. Lets say I have a coin and I flip it n times. If it lands on tails, I add one to x. Given a source of uniformly distributed numbers (0 to 1), how map it to a number between 0 and n so that the distribution of the random numbers is the same as the distribution of x? Also, please provide a more general way to do this for a biased coin, with probability of tails being t.

• This is the problem of generating binomial random variates. There is a lot of literature out there about this for you to explore. – Parcly Taxel Mar 24 '17 at 13:55

Your variable $x$ is distributed according to the binomial distribution with parameters $n$ and $t$.
Take a look at the generating binomial random variates section to find how to transform a uniformly distributed random number to your variable $x$.