Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into continuous_space
Browse files Browse the repository at this point in the history
  • Loading branch information
quaquel committed Jan 6, 2025
2 parents 73b8777 + 696923f commit 4f3073b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mesa/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions tests/test_model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Tests for model.py."""

import numpy as np

from mesa.agent import Agent, AgentSet
from mesa.model import Model

Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit 4f3073b

Please sign in to comment.