[Tutor] Initialising attributes with random values

Max Russell max_russell2000 at yahoo.co.uk
Tue Jul 5 13:05:45 CEST 2005

Hello there;

If I have a class and want to initalise it, with
random values assigned to the attributes, what is the
best way of doing this?

For example:

    def __init__(self, name, size = 0, strength = 0):
        self.name = name
        self.size = size
        self.strength = strength

starts with values of 0. But how can I neatly say,
start with a random value from (for example) 1 - 5?


How much free photo storage do you get? Store your holiday 
snaps for FREE with Yahoo! Photos http://uk.photos.yahoo.com

More information about the Tutor mailing list