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
From this output/input operator reference regarding the output operator:
Serializes the internal state of the pseudo-random number engine e as a sequence of decimal numbers separated by one or more spaces, and inserts it to the stream
ost
.
The stream could be any kind of output stream, for example an output string stream. You can then use the string that the string-streams created and pass it on to whatever serialization framework you need.
Or if the serialization framework support direct output/input stream operations, you can use it directly with the engine operators.