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
program starting



2012/8/26 Steven D'Aprano <steve+comp.lang.pyt...@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
>     else:
>         return DLIST
>
> the_list = select_list()
> the_item = random.choice(the_list)
>
>
>
> --
> Steven
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to