Last active
September 8, 2017 20:49
-
-
Save loliGothicK/ff58e7aac535687e6b355db7b66a0cf2 to your computer and use it in GitHub Desktop.
C++の乱数ライブラリが使いにくい話 ref: http://qiita.com/_EnumHack/items/25fc998873d1bc7d2276
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
std::random_device rd{}; | |
std::cout << rd() << std::endl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
std::random_device rd{}; | |
std::vector<std::uint32_t> vec(10); | |
std::generate( vec.begin(), vec.end(), std::ref(rd) ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
std::mt19937 mt; | |
std::cout << mt() << std::endl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
std::random_device rd; | |
std::mt19937 mt(rd()); | |
std::cout << mt() << std::endl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
std::random_device rd{}; | |
std::vector<std::uint32_t> vec(10); | |
std::generate( vec.begin(), vec.end(), std::ref(rd) ); | |
std::mt19937 mt(std::seed_seq(vec.begin(), vec.end())); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
std::mt19937 mt{ std::random_device{}() }; | |
std::uniform_int_distribution<int> dist(1, 6); | |
for ( int i = 0 ; i != 10 ; ++i ) | |
std::cout << dist(mt) << std::endl; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment