I tested the following mini example with MSVC 2017 on Win7:
#include <iostream>
#include <random>
int main()
{
std::random_device rd;
std::cout << "entropy: " << rd.entropy() << std::endl;
return 0;
}
To my surprise, it outputs "entropy: 32". This means that rd produces real-random numbers instead of pseudo-random numbers. I was expecting "entropy: 0". As far as I understand it, no finite-length code is capable of producing real-random numbers, it takes a real specially-designed physical device to do so. No such device is attached to my testing PC.
My question is: how std::random_device is implemented that it produces real-random number without special hardware support?
Aucun commentaire:
Enregistrer un commentaire