mt19937无法设置random_device

时间:2019-03-24 00:07:04

标签: c++ multithreading random mt19937

我的代码无法识别“生成器”而失败,但是我在C ++文件的顶部声明了它。我需要它是线程安全的,所以我用“ thread_local”声明了它:

#include <windows.h>
#include <iostream>
#include <random>

using namespace std;
thread_local mt19937 generator;

DWORD GenerateRandomNumber(DWORD dwMin, DWORD dwMax)
{
uniform_int_distribution <DWORD> distribution(dwMin, dwMax);
return distribution(generator);
}

int main() 
{
random_device rd;
generator(rd());
}

1 个答案:

答案 0 :(得分:-3)

mt19937::operator()不带参数。