mesa icon indicating copy to clipboard operation
mesa copied to clipboard

Seed initialisation - feature suggestion

Open ed-ij opened this issue 3 years ago • 0 comments

I have just made some comments in a discussion that have made me think the seed initialisation could be improved.

I noted that using the model initialisation:

class MyModel(Model):
    def __init__(self, var1, var2, seed):
        self.seed = seed
        if self.seed is None:
            self.seed = random.randrange(sys.maxsize)
        super().__init__(seed=self.seed)
        ...

would enable random behaviour of the model as normal but also allow the seed to be recorded through data collection if desired.

Would it not be useful to provide this functionality internally instead? I think it would be possible to just add if cls.seed is None: cls.seed = random.randrange(sys.maxsize) before cls.random = random.Random(cls._seed)

This would make the behaviour of model.reset_randomizer() more consistent as it would reset random number generator using the seed currently being used even if no seed had been given originally.

Are there situations where changing this would cause issues?

Originally posted by @edward-ij in https://github.com/projectmesa/mesa/discussions/1009#discussioncomment-764637

ed-ij avatar May 20 '21 17:05 ed-ij