Why do I get the same sequence for every run with std::random_device with mingw gcc4.8.1?

后端 未结 5 1649
野性不改
野性不改 2020-11-22 02:46

I use the following code to test the C++ library.

Why do I get the exact same sequence for every run of the compiled executable? Is

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-11-22 03:02

    From http://en.cppreference.com/w/cpp/numeric/random/random_device:

    Note that std::random_device may be implemented in terms of a pseudo-random number engine if a non-deterministic source (e.g. a hardware device) is not available to the implementation.

    I would expect a decent implementation to at least seed the RNG though.

    Edit: I suspect they deliberately chose to deliver the same sequence each time, to make obvious the fact that the stream wasn't as random as promised.

提交回复
热议问题