相关疑难解决方法(0)

为什么我使用mingw gcc4.8.1使用std :: random_device进行每次运行都会得到相同的序列?

我使用以下代码来测试c++ <random>库.

为什么每次运行已编译的可执行文件时都会得到完全相同的序列?rd()编译是确定性的吗?如何为每次运行获得不同的输出?

Windows 7 64位上的GCC 4.8.1.使用http://nuwen.net/mingw.html上的 MinGW发行版

编辑:我用Visual Studio测试了相同的代码.没有问题.输出是不确定的.这可能是我使用的mingw gcc 4.8.1中的一个错误.

#include <iostream>
#include <random>
using namespace std;
int main(){
 random_device rd;
 mt19937 mt(rd());
 uniform_int_distribution<int> dist(0,99);
 for (int i = 0; i< 16; ++i){
    cout<<dist(mt)<<" ";
 }
 cout <<endl;
}
Run Code Online (Sandbox Code Playgroud)

c++ random stl c++11

66
推荐指数
3
解决办法
2万
查看次数

标签 统计

c++ ×1

c++11 ×1

random ×1

stl ×1