According to the standard, std::random_device
works the following way:
result_type operator()();
Returns: A non-deterministic random value, uniformly distributed between
min()
andmax()
, inclusive. It is implementation-defined how these values are generated.
And there are a couple of ways you can use it. To seed an engine:
std::mt19937 eng(std::random_device{}());
As an engine in itself:
std::uniform_int_distribution<> uid(1, 10);
std::cout << dist(dev);
Because it is implementation-defined, it doesn't sound as strong as say std::seed_seq
or srand(time(nullptr))
. Do I prefer to use it as a seed, as an engine or not at all?