saving std.random RNG state
Neia Neutuladh
neia at ikeran.org
Tue Dec 18 01:18:48 UTC 2018
On Mon, 17 Dec 2018 22:20:54 +0000, harfel wrote:
> I am looking for a way to serialize/deserialize the state of the
> std.random.Random number generator, ideally using orange
> (https://github.com/jacob-carlborg/orange) or another serialization
> library. From looking at the module source code, I understand how to
> seed a random number generator with the state of another, but I do find
> a way to access the RNG's state, since it is hidden away in a private
> attribute. What is the recommended solution for this? Thanks in advance!
The .tupleof field allows you to access private members. This behavior
might eventually change, but probably not without a long deprecation
period.
If the struct stores everything by value:
cast(ubyte[])&rng[0..1];
If you have typeinfo available, you can check if the thing has pointers
with `(typeof(rng).flags & 1) == 0`. There's probably an equivalent in
std.traits that works at compile time.
More information about the Digitalmars-d-learn
mailing list