diff --git a/mesa/model.py b/mesa/model.py index 8263926a851..c507ed73a10 100644 --- a/mesa/model.py +++ b/mesa/model.py @@ -94,7 +94,7 @@ def __init__( self._seed = seed # this allows for reproducing stdlib.random try: - self.rng: np.random.Generator = np.random.default_rng(rng) + self.rng: np.random.Generator = np.random.default_rng(seed) except TypeError: rng = self.random.randint(0, sys.maxsize) self.rng: np.random.Generator = np.random.default_rng(rng) diff --git a/tests/test_model.py b/tests/test_model.py index ff1fe297b6a..a7e054d12b3 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -1,5 +1,7 @@ """Tests for model.py.""" +import numpy as np + from mesa.agent import Agent, AgentSet from mesa.model import Model @@ -37,6 +39,16 @@ def test_seed(seed=23): assert model2._seed == seed + 1 assert model._seed == seed + assert Model(seed=42).random.random() == Model(seed=42).random.random() + assert np.all( + Model(seed=42).rng.random( + 10, + ) + == Model(seed=42).rng.random( + 10, + ) + ) + def test_reset_randomizer(newseed=42): """Test resetting the random seed on the model."""