I generate random numbers in C++ using the following piece of code
std::random_device rdev {};
std::default_random_engine generator {rdev()};
std::uniform_int_distribution dist {a, b};
Similarly
std::default_random_engine generator {std::random_device{}()};
std::uniform_int_distribution dist {a, b};
What i'm trying to understand is the mechanics behind generating an engine using a seed value. random_device obtains a seed using various information from your operating system. This value is used to initialize an engine object. For the first snippet of code presented here, if rdev
is an object, why do we pass in that value in to the engine as rdev()
. Why are we using function notation on an object of a class ?
For the second snippet of code, how are we able to generate a std::random_device
object by just using the class name?
I'm not sure if my issue in understanding this is specific to random number generation or something bigger involving the C++ language itself.
Aucun commentaire:
Enregistrer un commentaire