I came across a weird behaviour of the ptython3's random module.
I'm running a genetic programming algorithm which uses a random number generator created by rng = random.Random(0) because I need to be able to repeat the runs (here the seed is zero as I'm debugging it right now with zero). The only calls on the rng are to the random() method. However I encountered that the algorithm does not run the same way every time (different solutions at different generations).
What is even more weird is, that when I print every generated number using this helper class
class R(random.Random):
def random(self):
r = super().random()
print(r)
return r
rng = R(0)
the last printed numbers differ but they are all from a set of (roughly) 5 to 6 numbers (e.g. 0.8710926419421733, 0.6578312458538799, ...). Some of the numbers occur significantly more often then the others.
What could be the cause of this weird nondeterminism? Could I miss something somewhere? Any general tips & tricks on using the random module?
Things to note: I'm using the pandas library (I'm doing some datamining with GP), which also means numpy. It all runs in a virtual environment isolated from the global packages. Is it possible that these are somehow interfering with the random module?
I would be more than glad to post the code but it's wired in a larger framework and I would have to post an immense amount of code.
Aucun commentaire:
Enregistrer un commentaire