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.