[Python-ideas] random.boolean or bernoulli

Raymond Hettinger raymond.hettinger at gmail.com
Thu Apr 21 20:46:54 CEST 2011


On Apr 21, 2011, at 8:30 AM, Joao S. O. Bueno wrote:
> 
> What about  just:
> 
> def chance(n=0.5):
>      return random() < n

Come on people.  This is junk and bad design.
Besides being unnecessary, trivial, opaque, and slow,
it has other issues like:
* no range checking for n<0 or n>1
* bad choice of argument name (p or x is used for probability
  while n is typically an integer representing a count)
* not obvious that it returns a boolean
* not obvious that a uniform distribution is presumed
* a name that will have difference interpretations for different
  people and make not make sense in a given context.
* no parallels in other languages (even Excel doesn't have this).
* it presumes that our users are not very bright
  and are in dire need of the language being dumbed down.

I'm amazed (and a little appalled) that the python-ideas crowd
would entertain adding this to a mature module like random.
Guido has had twenty years to put something like this in
the module (I believe he was the original writer) and likely
didn't do so for a good reason.  Even stats packages don't
seem to include anything this mundane.  The needs to be
some effort to not make modules unnecessarily fat and to
limit feature creep except for tools that greatly improve
expressive power.


Raymond


P.S.  Bernoulli isn't even jargon; it's a person's name.
A Bernoulli trial just means that events are independent.
It doesn't imply anything about a distribution or population
of possible result values.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110421/b826eafe/attachment.html>


More information about the Python-ideas mailing list