mercredi 26 février 2020

Safe to seed Python RNG using float?

Can floating point values be passed as an argument to random.seed()? Does this introduce unforeseen issues?

In other words. Is....

random.seed(0.99999999)
<use a few thousand random numbers>
random.seed(1)
<use a few thousand random numbers>

.... functionally equivalent to....

random.seed(0)
<use a few thousand random numbers>
random.seed(1)
<use a few thousand random numbers>

Quick testing suggests that both sets of code run just fine and on a superficial level the outputs appear to be independent and deterministic.

I'm interested to know if this method of seeding is completely safe to use in cases where independence between seeded sets is important. Obtaining deterministic results is also important. I've checked some of the documentation: Python 2.7 documentation and Python 3.8 documentation and done some googling and only found references to integers being used as a seed (or other data types which are converted to integers). I couldn't see any reference to floats and this makes me wonder if they are "safe" in the sense that they work in a predictable way with no nasty surprises.

I'm currently working with Python 2.7 but am interested in the answer for more modern versions too.




Aucun commentaire:

Enregistrer un commentaire