choosing random numbers with weights/probability?

kevinsl kevinsl at yahoo.com
Mon Jun 21 19:47:45 CEST 1999


I've been using the whrandom.choice routine and it's very
useful. But is there any way to add weights or
probabilities of being chosen to the items in the list?

example:

list=['one','two','three']
item=whrandom.choice(list)

Is there any way to say that 'one' and 'two' have a 25%
chance of being chosen, and 'three' has a 50% chance?

I'm hoping there's already a module to do this... or else
I'll be writing my own..

thanks,

Kevin



**** Posted from RemarQ - http://www.remarq.com - Discussions Start Here (tm) ****




More information about the Python-list mailing list