vendredi 9 juin 2023

Is there a way to use python 3.9 to emulate default rng from python 2.7?

I have a program which is implemented in Python 2.7 that I want to migrate to Python 3.9.

I want to use regression testing to check if the migration is successful and confirm that the new version is performing the same calculation as the old version.

However...

The program uses random.Random(seed) which the previous developer unwisely decided to seed with floating point numbers.

The code ports to python 3.9 easily but unfortunately it produces different random numbers (apart from instances where the float happens to be an integer). Fiddling around with the generators it looks like this is a consequence of the two versions using a different hash() method. It is not a consequence of changes in float point representation.

Is there a way to generate the same set of random numbers in Python 3.9 that would have been generated by that particular line of code in Python 2.7? i.e. How can I generate the result that legacy code random.Random(1.01) would produce without using a legacy interpreter?




Aucun commentaire:

Enregistrer un commentaire