samedi 23 décembre 2017

Python Random Global Instance vs Local Instances vary wildly

I'm building a simulation engine which requires me to use Random Distributions heavily. Initially I was using the global instance of random in Python, but then I noticed something weird.

I added another feature to the Simulation engine behind a feature flag. With the flag off it the engine should provide the same result. However, we did not add a call to random.uniform() behind the flag.

When we ran the engine with the flag off, the results were drastically (5-10%) different than before. After removing the call to random.uniform() it was back to the previous results.

I know that the same PRNG returns worse results over time, but the number of calls to it cannot be more than a 100k.

Are there any best practices to using Python's random (like seeding, reuse global instance or always create new ones)? Or should we skip it and maybe use Numpy? Because of the drastic variation it is hard to tell which results are correct and which are wrong.




Aucun commentaire:

Enregistrer un commentaire