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
- What object can be used to store the state of the mersenne_twister_engine that can also be serialized using Boost?
- Is my approach safe and generally considered to be good practice?
- Is there an approach to this that is generally considered to be better?