Repository: projectmesa/mesa

Issue:
Seed and random should not be class attributes
**Describe the bug**
<!-- A clear and concise description the bug -->

Every time a model instance is created, it updates the seed and random attribute of every other instance of the same class.

**Expected behavior**
<!-- A clear and concise description of what you expected to happen -->

I would expect each instance to have their own attribute. This way, the behavior of each instance is independent and predictable.

**To Reproduce**
<!-- Steps to reproduce the bug, or a link to a project where the bug is visible -->

```pycon
>>> from mesa import Model
>>> class Ex(Model):
...   def __init__(self, seed=2):
...     pass
...
>>> a = Ex(seed=1)
>>> print(a._seed, a.random)
1 <random.Random object at 0x282a8d0>
>>> b = Ex(seed=2)
>>> print(a._seed, a.random)
2 <random.Random object at 0x282b2d0>
```

Discussion:
rht: The solution looks good. The remaining blocker to this PR being merged is that you need to format your changes with `black`.
rht: Sorry, one more request, do you mind squashing your commits to 1?
balkian: Sure. I hope I've done it right :)
rht: LGTM

Patch:
diff --git a/mesa/model.py b/mesa/model.py
index 10b0a5ee..aba1db9a 100644
--- a/mesa/model.py
+++ b/mesa/model.py
@@ -21,9 +21,10 @@ class Model:
 
     def __new__(cls, *args: Any, **kwargs: Any) -> Any:
         """Create a new model object and instantiate its RNG automatically."""
-        cls._seed = kwargs.get("seed", None)
-        cls.random = random.Random(cls._seed)
-        return object.__new__(cls)
+        obj = object.__new__(cls)
+        obj._seed = kwargs.get("seed", None)
+        obj.random = random.Random(obj._seed)
+        return obj
 
     def __init__(self, *args: Any, **kwargs: Any) -> None:
         """Create a new model. Overload this method with the actual code to


Test patch:
diff --git a/tests/test_model.py b/tests/test_model.py
index a326978d..35ebb4a0 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -28,6 +28,9 @@ def test_running():
 def test_seed(seed=23):
     model = Model(seed=seed)
     assert model._seed == seed
+    model2 = Model(seed=seed + 1)
+    assert model2._seed == seed + 1
+    assert model._seed == seed
 
 
 def test_reset_randomizer(newseed=42):