Author rhettinger
Recipients Serge Anuchin, mark.dickinson, pitrou, r.david.murray, rhettinger, serhiy.storchaka, skrah, steven.daprano, tim.peters, vstinner
Date 2015-07-12.07:50:36
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
> 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:37rhettingersetrecipients: + rhettinger, tim.peters, mark.dickinson, pitrou, vstinner, steven.daprano, r.david.murray, skrah, serhiy.storchaka, Serge Anuchin
2015-07-12 07:50:37rhettingersetmessageid: <>
2015-07-12 07:50:37rhettingerlinkissue24567 messages
2015-07-12 07:50:37rhettingercreate