我的代码无法识别“生成器”而失败,但是我在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());
}