首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何保存/检索mt19937,以便重复该序列?

如何保存/检索mt19937,以便重复该序列?
EN

Stack Overflow用户
提问于 2017-12-01 04:30:09
回答 0查看 30关注 0票数 0

这是我的尝试

代码语言:javascript
复制
using namespace std;

int main()
{
    mt19937 mt(time(0));

    cout << mt() << endl;
    cout << "----" << endl;

    std::ofstream ofs;
    ofs.open("/path/save", ios_base::app | ifstream::binary);
    ofs << mt;
    ofs.close();

    cout << mt() << endl;
    cout << "----" << endl;

    std::ifstream ifs;
    ifs.open("/path/save", ios::in | ifstream::binary);
    ifs >> mt;
    ifs.close();

    cout << mt() << endl;

    return 0;
}

以下是可能的输出

代码语言:javascript
复制
1442642936
----
1503923883
----
3268552048

我原以为最后两个数字是一样的。显然,我无法写入和/或读取我的mt19937。你能帮助修复这段代码吗?

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47582071

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档