[issue18844] allow weights in random.choice
Madison May
report at bugs.python.org
Sun Sep 1 16:37:04 CEST 2013
Madison May added the comment:
[Raymond Hettinger]
> The sticking point is going to be that we don't want to recompute the
> cumulative weights for every call to weighted_choice.
> So there should probably be two functions:
> cw = make_cumulate_weights(weight_list)
> x = choice(choice_list, cw)
That's pretty much how I broke things up when I decided to test out optimization with lru_cache. That version of the patch is now attached.
[Serhiy Storchaka]
> I like the idea about adding a family of distribution generators.
> They should check input parameters and make a precomputation and then > generate infinite sequence of specially distributed random numbers.
Would these distribution generators be implemented internally (see attached patch) or publicly exposed?
----------
Added file: http://bugs.python.org/file31546/weighted_choice_v2.diff
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18844>
_______________________________________
More information about the Python-bugs-list
mailing list