use : random.randint(1,5)
so complete code will be: class something: def __init__(self, name): self.name = name self.size = random.randint(1,5) self.strength = random.randint(1,5) pujo On 7/5/05, Max Russell <[EMAIL PROTECTED]> wrote: > 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? > > thanks > Max > > > > ___________________________________________________________ > How much free photo storage do you get? Store your holiday > snaps for FREE with Yahoo! Photos http://uk.photos.yahoo.com > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor