dimanche 31 mai 2020

How can a mersenne_twister_engine be serialized using Boost?

I have a class that implements std::mt19937 and I would like to be able to save and load the state of the random number generator for consistency. I'm aware that the << and >> operators can be used to save/load the engine's state and that I can separate the save and load functions when I archive the file if necessary. My guess at how to do this would be to use the << and >> operators to store the state into/extract the state from an object that can be serialized. My questions are

  1. What object can be used to store the state of the mersenne_twister_engine that can also be serialized using Boost?
  2. Is my approach safe and generally considered to be good practice?
  3. Is there an approach to this that is generally considered to be better?



Aucun commentaire:

Enregistrer un commentaire