Skip to content

Instantly share code, notes, and snippets.

@loliGothicK
Last active September 8, 2017 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loliGothicK/ff58e7aac535687e6b355db7b66a0cf2 to your computer and use it in GitHub Desktop.
Save loliGothicK/ff58e7aac535687e6b355db7b66a0cf2 to your computer and use it in GitHub Desktop.
C++の乱数ライブラリが使いにくい話 ref: http://qiita.com/_EnumHack/items/25fc998873d1bc7d2276
std::random_device rd{};
std::cout << rd() << std::endl;
std::random_device rd{};
std::vector<std::uint32_t> vec(10);
std::generate( vec.begin(), vec.end(), std::ref(rd) );
std::mt19937 mt;
std::cout << mt() << std::endl;
std::random_device rd;
std::mt19937 mt(rd());
std::cout << mt() << std::endl;
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()));
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