<br>Thanks for helps<br><br><br>This code almost meets my needs .<br>But not accurate probability when not enough source elements.<br><br>So I give up the not enough elements situation.<br>For source list is growing fast,  the bast situation just appear in the program starting <br>
<br><br><br><div class="gmail_quote">2012/8/26 Steven D'Aprano <span dir="ltr"><<a href="mailto:steve+comp.lang.python@pearwood.info" target="_blank">steve+comp.lang.python@pearwood.info</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 08/25/2012 12:03 PM, 月忧茗 wrote:<br>
<br>
</div><div class="im">> In the FinalList,<br>
> probability of ALIST's item appeared  is  43% probability of BLIST's<br>
> item appeared  is  37% probability of CLIST's item appeared  is  19%<br>
> probability of DLIST's item appeared  is  1%<br>
<br>
</div>First, select one of the four lists with those appropriate probabilities.<br>
Then once you selected a list, select one of its items randomly.<br>
<br>
import random<br>
<br>
def select_list():<br>
    x = random.randint(1, 100)<br>
    if x <= 43:<br>
        return ALIST<br>
    elif x <= 80:  # 43 + 37<br>
        return BLIST<br>
    elif x <= 99:  # + 19<br>
        return CLIST<br>
    else:<br>
        return DLIST<br>
<br>
the_list = select_list()<br>
the_item = random.choice(the_list)<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
<br>
--<br>
Steven<br>
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></span></blockquote></div><br>