Raymond Hettinger added the comment:
> In sample() the selected set can be initialized to {n}
I originally used the {n} approach but it was less clear and it lead to a
re-selection rather than undoing the rounding. That would change the output.
> I like Tim's suggestion about import-time patching.
Sorry, but there's a limit to how much I'm willing to garbage-up the code over
this issue.
> In choice() I would write the condition as "i == n > 0" to
> avoid indexing with negative index
I'll write that as "'i == n and n > 0" which reads better and runs faster in
the common case (look at the disassembly of each).
Attaching a revised patch.
> here's another timing variation:
>
> i = int(random() * n)
> return seq[i - (i == n)]
This ran a little slower than the conditional approach.
----------
Added file: http://bugs.python.org/file39908/handle_double_rounding3.diff
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue24567>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com