how to choose element from list based on probabilities?

Matthew Wilson mwilson at sarcastic-horse.com
Thu Nov 13 16:59:48 EST 2003


I have a list of very simple circle objects:

class Circle:
    def __init__(self, x,y,r):
        self.center =(x,y)
        self.r = r

I want to write a function that accepts a list of circle objects and
then chooses one of the circles and returns that circle.  The circles
with the biggest areas should be the most likely to be chosen, but there
should be some randomness.

Subsequent calls to the function should not return the same circle.

Can anyone help me out?




More information about the Python-list mailing list