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 <rep...@bugs.python.org> <http://bugs.python.org/issue18844> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com