yueyoum at gmail.com
Sun Aug 26 06:44:00 CEST 2012
Thanks for helps
This code almost meets my needs .
But not accurate probability when not enough source elements.
So I give up the not enough elements situation.
For source list is growing fast, the bast situation just appear in the
2012/8/26 Steven D'Aprano <steve+comp.lang.python at pearwood.info>
> On 08/25/2012 12:03 PM, 月忧茗 wrote:
> > In the FinalList,
> > probability of ALIST's item appeared is 43% probability of BLIST's
> > item appeared is 37% probability of CLIST's item appeared is 19%
> > probability of DLIST's item appeared is 1%
> First, select one of the four lists with those appropriate probabilities.
> Then once you selected a list, select one of its items randomly.
> import random
> def select_list():
> x = random.randint(1, 100)
> if x <= 43:
> return ALIST
> elif x <= 80: # 43 + 37
> return BLIST
> elif x <= 99: # + 19
> return CLIST
> return DLIST
> the_list = select_list()
> the_item = random.choice(the_list)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list