#include <iostream>
#include <random>
#include <ctime>
bool checkCPU(void);
int getRand(void);
int main(int argc, char* argv[])
{
using namespace std;
int x, y, m;
cout << "input a value K:";
cin >> x;
cout << "input the Dimension:";
cin >> y;
if (checkCPU())
{
cout << "using CPU Digital Random Number Generator" << endl;
for (int index = 0; index <= (x * y); index++ )
{
m = getRand();
cout << m << endl;
}
}
else
{
cout << "not support DRNG,using mt19937" << endl;
std::mt19937 rnd((unsigned int)time(0));
for (int index = 0; index <= (x * y); index++)
{
m = rnd();
cout << m << endl;
}
}
return 0;
}
int getRand(void)
{
int result;
__asm
{
RDRAND eax
mov result,eax
}
return result;
}
bool checkCPU(void)
{
bool flag = 0;
__asm
{
mov eax, 1
cpuid
and eax, 0x20000000 //30th bit
test eax, 0
jnz L
mov flag, -1
L:
}
return flag;
}