Sprout.Random で乱数の種を設定

Sprout.Random で乱数の種を設定する場合、乱数エンジンのコンストラクタに整数値で種を渡します。
また、SPROUT_UNIQUE_SEED マクロを使用する事でコンパイル毎に違う値の種を設定する事が出来ます。

[ソース]

#include <sprout/random.hpp>
#include <iostream>
#include <boost/mpl/print.hpp>

int
main(){
    static constexpr sprout::uniform_int_distribution<int> dist(100, 999);

    {
        static constexpr auto seed = 2013;
        static constexpr sprout::default_random_engine engine(seed);

        static_assert(engine() == 33832491, "");
        static_assert(dist(engine) == 114, "");
    }

    {
        static constexpr auto seed = 8379842;
        static constexpr sprout::default_random_engine engine(seed);

        static_assert(engine() == 1253567439, "");
        static_assert(dist(engine) == 625, "");
    }

    {
        static constexpr auto seed = SPROUT_UNIQUE_SEED;
        std::cout << seed << std::endl;

        static constexpr sprout::default_random_engine engine(seed);
        std::cout << engine() << std::endl;
        std::cout << dist(engine) << std::endl;

        // コンパイル毎に違う値が出力される
        typedef boost::mpl::print<boost::mpl::int_<seed>>::type unique_seed_type;
        typedef boost::mpl::print<boost::mpl::int_<engine()>>::type engine_type;
        typedef boost::mpl::print<boost::mpl::int_<dist(engine)>>::type dist_type;
    }

    return 0;
}

[出力]

2600914310
1537173485
744


こんな感じでコンパイル毎に違う乱数を生成する事も出来ます。
便利。