jeudi 15 octobre 2020

How to force all instances of Random generate same sequence of numbers in different runs?

I'm writing an application for testing an algorithm with random generated inputs. This involves several instances of Random class spread around the code. I need all these instances to generate same inputs in different runs to debug the algorithm when I find an unexpected result. This is the behavior of the apps created with Delphi, unless you manually call Randomize.

I know I can:

  • Provide constant seeds for all created instances.
  • Pass a unique instance, which is created with a constant seed, to all methods that need a random generator.

The reason I prefer not to use any of the above methods is that most of the functions that generate random data are kind of black box functions that are collected here and there on the Internet. Some of them even use several random generators for unknown reasons. I prefer not to mess with these functions unless I really have to.

So, are there any other ways to control all these instances together?

Aucun commentaire:

Enregistrer un commentaire