lundi 25 juin 2018

Why would you increment a RNG seed?

I've seen code of the following kind (in a unit test) and I was wondering what could be the motivation behind it:

int seed = GetMySeed()
Something(seed++)
SomethingElse(seed++)
YetSomethingElse(seed++)

Now, if the three functions called were the same, I could image scenarios where you want this, e.g. creating multiple instances of an object with a different seed. However, in my mind, the direct modification of a seed feels like bad practice. Even if I had reasons to modify the seed, it would seem more natural to me to write:

int seed = GetMySeed()
TheSameThing(seed)
TheSameThing(seed + 1)
TheSameThing(seed + 2)

What might be the reason you would increment the seed?




Aucun commentaire:

Enregistrer un commentaire