Skip to content

Commit

Permalink
Fix random issue (#138)
Browse files Browse the repository at this point in the history
* Fix randomness issue by forcing seed resets

* Changelog
  • Loading branch information
nikhilwoodruff authored Dec 21, 2023
1 parent f3fae34 commit c234fde
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions changelog_entry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- bump: patch
changes:
fixed:
- Randomness issue.
10 changes: 5 additions & 5 deletions policyengine_core/commons/formulas.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,14 @@ def amount_between(
return clip(amount, threshold_1, threshold_2) - threshold_1


def random(entity, reset=False):
if entity.simulation.has_axes:
# Generate the same random number for each entity.
random_number = np.random.rand(1)[0]
return np.array([random_number] * entity.count)
def random(entity, reset=True):
if reset:
np.random.seed(0)
x = np.random.rand(entity.count)
if entity.simulation.has_axes:
# Generate the same random number for each entity.
random_number = x[0]
return np.array([random_number] * entity.count)
return x


Expand Down

0 comments on commit c234fde

Please sign in to comment.