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.但是,如果無法使用此類來源,則實施可能會訴諸偽隨機數字引擎。這可以解釋使用mingw gcc 4.8.1觀察到的確定性行為。
重要的是要注意,不保證隨機_device提供真正的隨機性。某些實施方式,例如MINGW GCC 4.8.1中的實現,可以故意提供固定的序列以證明流的非隨機性。為每次運行獲取不同的輸出,應該考慮使用隨機數生成器的播種方法,例如根據當前時間或某個cryptographics hass of Some userust putput使用種子,例如使用種子。
免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。
Copyright© 2022 湘ICP备2022001581号-3