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 committed Sep 21, 2023
1 parent 3dbabfe commit 0e68333
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion mesa/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# Remove this __future__ import once the oldest supported Python is 3.10
from __future__ import annotations

import datetime

Check failure on line 10 in mesa/model.py

View workflow job for this annotation

GitHub Actions / lint-ruff

Ruff (F401)

mesa/model.py:10:8: F401 `datetime` imported but unused
import random

# mypy
Expand All @@ -21,7 +22,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()

Check failure on line 29 in mesa/model.py

View workflow job for this annotation

GitHub Actions / lint-ruff

Ruff (S311)

mesa/model.py:29:25: S311 Standard pseudo-random generators are not suitable for cryptographic purposes
obj.random = random.Random(obj._seed)
return obj

Expand Down

0 comments on commit 0e68333

Please sign in to comment.