Probability Algorithm
月忧茗
yueyoum at gmail.com
Sun Aug 26 00:44:00 EDT 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
program starting
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
> else:
> return DLIST
>
> the_list = select_list()
> the_item = random.choice(the_list)
>
>
>
> --
> Steven
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120826/407c5556/attachment.html>
More information about the Python-list
mailing list