boost::random の使い方
あれー、おかしいなぁと思ってたらひどいことになっていた。
#include <boost/random.hpp> using namespace std; using namespace boost; int main() { mt19937 gen(static_cast<unsigned long>(10)); for (int i = 0; i < 10; i++) { cout << variate_generator<mt19937, uniform_smallint<> > (gen, uniform_smallint<>(0, 10))() << endl; } }
% ./a 6 6 6 6 6 6 6 6 6 6
寂しい。ちゃんと使い方読まないとダメだなぁ。
追記:
こうすんのね。
#include <boost/random.hpp> using namespace std; using namespace boost; int main() { mt19937 gen(static_cast<unsigned long>(10)); for (int i = 0; i < 10; i++) { cout << uniform_smallint<>(0, 10)(gen) << endl; } }