Message246639
> 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. |
|
Date |
User |
Action |
Args |
2015-07-12 07:50:37 | rhettinger | set | recipients:
+ rhettinger, tim.peters, mark.dickinson, pitrou, vstinner, steven.daprano, r.david.murray, skrah, serhiy.storchaka, Serge Anuchin |
2015-07-12 07:50:37 | rhettinger | set | messageid: <1436687437.45.0.914800994943.issue24567@psf.upfronthosting.co.za> |
2015-07-12 07:50:37 | rhettinger | link | issue24567 messages |
2015-07-12 07:50:37 | rhettinger | create | |
|