[英]How can a mersenne_twister_engine be serialized using Boost?
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.我有一个实现 std::mt19937 的 class 并且我希望能够保存和加载随机数生成器的 state 以保持一致性。 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.我知道 << 和 >> 运算符可用于保存/加载引擎的 state,并且在必要时存档文件时可以将保存和加载功能分开。 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.我对如何做到这一点的猜测是使用 << 和 >> 运算符将 state 存储到可以序列化的 object 中/从 state 中提取。 My questions are我的问题是
From this output/input operator reference regarding the output operator:从这个关于 output 运算符的输出/输入运算符参考:
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
.将伪随机数引擎 e 的内部 state 序列化为由一个或多个空格分隔的十进制数序列,并将其插入到 streamost
中。
The stream could be any kind of output stream, for example an output string stream . 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.或者,如果序列化框架支持直接输出/输入 stream 操作,您可以直接与引擎操作符一起使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.