Skip to content

Commit

Permalink
model: Ensure the seed is initialized with current timestamp when it …
Browse files Browse the repository at this point in the history
…is None
  • Loading branch information
rht authored and Corvince committed Sep 26, 2023
1 parent a75a353 commit 6a39efd
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion mesa/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ class Model:
def __new__(cls, *args: Any, **kwargs: Any) -> Any:
"""Create a new model object and instantiate its RNG automatically."""
obj = object.__new__(cls)
obj._seed = kwargs.get("seed", None)
obj._seed = kwargs.get("seed")
if obj._seed is None:
# We explicitly specify the seed here so that we know its value in
# advance.
obj._seed = random.random() # noqa: S311
obj.random = random.Random(obj._seed)
return obj

Expand Down

0 comments on commit 6a39efd

Please sign in to comment.