Boost logo

Boost Users :

Subject: Re: [Boost-users] [random] saving state of generator
From: Gabriel Redner (gredner_at_[hidden])
Date: 2012-01-31 15:23:06

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."



On Tue, Jan 31, 2012 at 2:20 AM, Thomas Mang <thomasmang.ng_at_[hidden]> 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_at_[hidden]

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at