【发布时间】:2021-04-23 14:20:24
【问题描述】:
编译后,程序总是返回相同的结果。出乎意料的是,代码在 Linux 上可以正常运行...
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> distribut(1, 6);
for (int i=0; i < 10; i++)
{
std::cout << distribut(gen) << ' ';
}
编译器规范:
❯ g++ --version
g++.exe (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 8.1.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
【问题讨论】:
-
std::random_device可能每次都给std::mt19937提供相同的种子,因为有些实现只是return constant; -
阅读gcc.gnu.org/bugzilla/show_bug.cgi?id=85494“无论如何,它应该在gcc-9-branch中为mingw-w64修复,所以对于GCC 9.2版本”跨度>
标签: c++ linux windows random g++