Why do I get the same sequence from std::random_device with MinGW GCC 4.8.1?
In the provided code, an instance of std::random_device (rd) is used as the seed for a Mersenne Twister engine (mt). However, the observed behavior of obtaining the same sequence of random numbers with every run suggests that the rd may not be providing a truly random seed.
According to the documentation (http://en.cppreference.com/w/cpp/numeric/random/random_device), std::random_device is designed to access non-deterministic hardware sources for randomness. However, if such a source is unavailable, the implementation may resort to a pseudo-random number engine. This could explain the deterministic behavior observed with MinGW GCC 4.8.1.
It is important to note that random_device is not guaranteed to provide true randomness. Some implementations, like the one in MinGW GCC 4.8.1, may deliberately deliver a fixed sequence to demonstrate the non-randomness of the stream.
To obtain different output for each run, one should consider alternative methods of seeding the random number generator, such as using a seed based on the current time or a cryptographic hash of some user input.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3