random.choices() Suggest that the code confirm that cum_weights sequence is in ascending order

Chris Angelico rosuav at gmail.com
Mon May 14 08:27:24 EDT 2018


On Mon, May 14, 2018 at 9:59 PM, Paul Moore <p.f.moore at gmail.com> wrote:
> The problem is that supplying cum_weights allows the code to run in
> O(log n) by using bisection. This is significantly faster on large
> populations. Adding a test that the cumulative weights are
> nondecreasing would add an O(n) step to the code.
>

Hang on - are the 'n' and 'log n' there referring to the same n?

ChrisA



More information about the Python-list mailing list