diff --git a/changelog_entry.yaml b/changelog_entry.yaml index e69de29b..cacec347 100644 --- a/changelog_entry.yaml +++ b/changelog_entry.yaml @@ -0,0 +1,6 @@ +- bump: patch + changes: + fixed: + - Removed the possibility of a negative seed in random() within commons/formulas.py + changed: + - As part of the negative seed fix in formulas.py, a single seed and generator was used to generate a random sequence, rather than a random number generator and seed combination being deployed for each entity id. This saves around 5-10 seconds of computation. diff --git a/policyengine_core/commons/formulas.py b/policyengine_core/commons/formulas.py index 4695cf9c..74178747 100644 --- a/policyengine_core/commons/formulas.py +++ b/policyengine_core/commons/formulas.py @@ -329,13 +329,8 @@ def random(population): entity_ids = population(f"{population.entity.key}_id", period) # Generate random values for each entity - values = np.array( - [ - np.random.default_rng( - seed=id * 100 + population.simulation.count_random_calls - ).random() - for id in entity_ids - ] + values = np.random.default_rng(seed=min(entity_ids)).random( + size=len(entity_ids) ) return values