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