# Given Bernoulli probability, how to draw a Bernoulli from a uniform distribution [duplicate]

I have a set of probability corresponding to Bernoulli experiment. How to draw Bernoulli random number given these specific probability from a uniform(0,1) distribution. I know we can draw from binom, but using uniform distribution can vectorize the operation and make it so much faster.

## 1 Answer

It sounds like you're asking how to simulate independent draws from a Bernoulli distribution with a given probability $p$ when all you have is independent draws from a uniform distribution on $[0, 1]$. That's easy: for each value $x$ drawn from the uniform distribution, return 1 if $x < p$ and 0 otherwise.

• Why is that Bernoulli number? Can you explain it a bit more?
– MLE
Oct 15, 2016 at 1:06
• Why is the result Bernoulli-distributed, you mean? Because all that's required is to return 1 with probability $p$, and the uniform distribution on $[0, 1]$ means that the chance of $x$ landing in $[0, p]$ is $p$. Oct 15, 2016 at 1:09
• Yes, why the result is Bernoulli distributed why when x<p, return 1. Still very confused. Why "the uniform distribution on [0,1][0,1] means that the chance of xx landing in [0,p][0,p] is p"
– MLE
Oct 15, 2016 at 1:53
• Because that's how the uniform distribution is defined. I'm not sure what more there is to say without getting into measure theory or something, which I doubt you would find enlightening. Oct 15, 2016 at 3:05