def line is only run once, evaluating the expressions there and saving the results before any instances of
dungeonRoom are instantiated.
You could think of that code having a static initializer which creates constants:
_init_height=random.randint(3,9) _init_width=random.randint(3,9) _init_origin=random.randint(100,300)
Then it just uses them when creating new
dungeonRooms as follows:
def __init__(self, height=_init_height, width=_init_width, origin=_init_origin): ...
Can you just move the random calls into the contents of the
def __init__(self, arg=None): if arg is None: self.arg=random.randint(3,9) else: self.arg=arg
(More info here if you want.)