dimanche 9 juin 2019

random.random() generates different numbers on different machines

on a raspberry pi 3:

>>> import random
>>> random.seed(0.9849899567458751)
>>> random.random()
0.47871160253065614

on my laptop (running Ubuntu):

>>> import random
>>> random.seed(0.9849899567458751)
>>> random.random()
0.5059711320067936

I need those two numbers to be equal. My guess would be that this has something to do with floating point precision that might be different on the two machines but I don't know how to solve this.

How do I generate reproducable random numbers in python, regardless of the machine the code is running on?




Aucun commentaire:

Enregistrer un commentaire