[random] saving state of generator
Hi, Consider an application intended to run for weeks and where a deterministic sequence of random numbers is needed (deterministic in order to make results 100% reproduceable). For hardware-related reasons that application might get halted (killed). In order to smoothly restart the application I would like to regularly save the complete system state and can hence use that as restore point. That complete save works for everything except the random number generator - I am using boost::random::mt19937. The mt199937 class does not seem to offer such an option (full state save). Using serialization also does not sound great in my eyes as I am, of course, not familiar with the internal representation of mt19937. So what is the best option? Dissecting mt19937 (intrusive changes to class template mersenne_twister_engine) and making my own serialization routine? Any other / more straightforward ideas? thanks Thomas
Hi Thomas, The << and >> operators are the right way to save and restore the PRNG state. From the docs: "Classes which model a pseudo-random number generator should also model the Streamable concept, i.e. implement operator<< and operator>>. If so, operator<< writes all current state of the pseudo-random number generator to the given ostream so that operator>> can restore the state at a later time. The state shall be written in a platform-independent manner, but it is assumed that the locales used for writing and reading be the same. The pseudo-random number generator with the restored state and the original at the just-written state shall be equivalent." (http://www.boost.org/doc/libs/1_48_0/doc/html/boost_random/reference.html#bo...) -Gabe On Tue, Jan 31, 2012 at 2:20 AM, Thomas Mang <thomasmang.ng@gmail.com> wrote:
Hi,
Consider an application intended to run for weeks and where a deterministic sequence of random numbers is needed (deterministic in order to make results 100% reproduceable). For hardware-related reasons that application might get halted (killed). In order to smoothly restart the application I would like to regularly save the complete system state and can hence use that as restore point. That complete save works for everything except the random number generator - I am using boost::random::mt19937. The mt199937 class does not seem to offer such an option (full state save). Using serialization also does not sound great in my eyes as I am, of course, not familiar with the internal representation of mt19937. So what is the best option? Dissecting mt19937 (intrusive changes to class template mersenne_twister_engine) and making my own serialization routine? Any other / more straightforward ideas?
thanks Thomas
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Gabriel Redner
-
Thomas Mang