[Python-ideas] random.boolean or bernoulli

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Apr 21 13:46:46 CEST 2011


Erich Blume wrote:

> def bernoulli(p):
>     return random() <= p

When I use a function like this I've been calling
it chance(), which seems less jargony.

> def boolean():
>     return choice((True,False))

Since this is equal to chance(0.5), I'm not sure
it's worth it. A chance of exactly 50% seems like
a rather special case.

-- 
Greg



More information about the Python-ideas mailing list