[issue46190] Omit k in random.sample()

Raymond Hettinger report at bugs.python.org
Wed Dec 29 02:27:29 EST 2021


Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:

> My suggestion is not to set k=1 when omitted but to assign it a random value 

Sorry, I think that is just bizarre.  Also, some populations are *very* large, so a minor user accident of omitting a parameter would result in a large unexpected output.  For choices(), it would have been nice to have k default the population size (because resampling is a common use case) but we didn't go that path because of the likelihood of a large unexpected output.  The same reasoning holds here a well.

If you want to go down this path, I recommend making your code explicit about what it is trying to do.  Something this unexpected should not be the implicit and default behavior.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46190>
_______________________________________


More information about the Python-bugs-list mailing list