From 3b2c6a3db5a4362c575d229271a3f331766a9309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Mon, 27 Jul 2020 11:49:04 +0200 Subject: [PATCH] Seed before env initialization Fixes #6 --- CHANGELOG.md | 3 +++ soil/VERSION | 2 +- soil/environment.py | 5 +++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e53de5..f2975d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.14.9] +### Changed +* Seed random before environment initialization ## [0.14.8] ### Fixed * Invalid directory names in Windows gsi-upm/soil#5 diff --git a/soil/VERSION b/soil/VERSION index 13a0c2a..bf61a07 100644 --- a/soil/VERSION +++ b/soil/VERSION @@ -1 +1 @@ -0.14.8 \ No newline at end of file +0.14.9 \ No newline at end of file diff --git a/soil/environment.py b/soil/environment.py index a0b3d7d..81ef1b1 100644 --- a/soil/environment.py +++ b/soil/environment.py @@ -44,6 +44,8 @@ class Environment(nxsim.NetworkEnvironment): topology=None, *args, **kwargs): self.name = name or 'UnnamedEnvironment' + seed = seed or time.time() + random.seed(seed) if isinstance(states, list): states = dict(enumerate(states)) self.states = deepcopy(states) if states else {} @@ -55,12 +57,11 @@ class Environment(nxsim.NetworkEnvironment): self.interval = interval self._history = history.History(name=self.name, backup=True) + self['SEED'] = seed # Add environment agents first, so their events get # executed before network agents self.environment_agents = environment_agents or [] self.network_agents = network_agents or [] - self['SEED'] = seed or time.time() - random.seed(self['SEED']) @property def agents(self):