[Python-ideas] random.boolean or bernoulli

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Apr 22 02:17:34 CEST 2011


Stephen J. Turnbull wrote:
> I'd simply use application-specific definitions like
> 
> def random_gender():
>     return 'female' if random() < p else 'male'

The benefit of chance() is that it saves you from having
to think "Should that be < p or > p?", and readers of the
code thinking "Now does that mean a probability of p or
1-p?"

The answers to those questions might be second nature
to you, but it's not necessarily so for others.

-- 
Greg



More information about the Python-ideas mailing list