lundi 19 avril 2021

numpy.random generates different numbers if main file is changed

I am using numpy.random.seed to set a seed before a simulation by events loop. The seed works as expected as long I don't change the file that calls and runs the simulation, but if change that file in any way the results of the simulation change (before or after the call from the function).

I have a file called runTest that calls a function that runs the simulation. One of the inputs of the function is a seed, which is set inside the function.

As I understand seeds, correct if I am wrong, after setting a seed nothing before or after it should affect its behaviour as long as I dont change or add functions using the seed.

The code is a 4000lines approx library where many import/exports are called, and I couldn't reproduce the error with a smaller code.

The only random library used is numpy.random, and scipy.stats that I read uses the same universal seed from numpy.random.seed.

I know it is now recommended to use from numpy.random import default_rng, but I already wrote my code, and it would be difficult to change how it works from a global seed to a object seed for each random distribution.




Aucun commentaire:

Enregistrer un commentaire