diff --git a/libs/random/example/array.cpp b/libs/random/example/array.cpp index fab28b54..debe733a 100644 --- a/libs/random/example/array.cpp +++ b/libs/random/example/array.cpp @@ -1,36 +1,34 @@ -// -// Sprout C++ Library -// -// Copyright (c) 2013 -// bolero-MURAKAMI : http://d.hatena.ne.jp/boleros/ -// osyo-manga : http://d.hatena.ne.jp/osyo-manga/ -// -// Readme: -// https://github.com/bolero-MURAKAMI/Sprout/blob/master/README -// -// License: -// Boost Software License - Version 1.0 -// -// -#include -#include -#include - -int -main(){ - static constexpr sprout::default_random_engine engine; - static constexpr sprout::uniform_smallint dist(1, 6); - - static constexpr sprout::array result = sprout::generate( - // Result type - sprout::array{}, - // Random generator - sprout::random::combine(engine, dist) - ); - - static_assert( - result == sprout::make_array(1, 1, 5, 2, 4, 2, 6, 2, 5, 1), - ""); - - return 0; -} +// +// Sprout C++ Library +// +// Copyright (c) 2013 +// bolero-MURAKAMI : http://d.hatena.ne.jp/boleros/ +// osyo-manga : http://d.hatena.ne.jp/osyo-manga/ +// +// Readme: +// https://github.com/bolero-MURAKAMI/Sprout/blob/master/README +// +// License: +// Boost Software License - Version 1.0 +// +// +#include +#include +#include + +int +main(){ + static constexpr sprout::default_random_engine engine; + static constexpr sprout::uniform_smallint dist(1, 6); + + static constexpr auto result = sprout::generate + /* Result type */> + (sprout::random::combine(engine, dist) /*Random generator*/) + ; + + static_assert( + result == sprout::make_array(1, 1, 5, 2, 4, 2, 6, 2, 5, 1), + ""); + + return 0; +} diff --git a/libs/random/example/distribution.cpp b/libs/random/example/distribution.cpp index b78b098f..e7268845 100644 --- a/libs/random/example/distribution.cpp +++ b/libs/random/example/distribution.cpp @@ -1,60 +1,60 @@ -// -// Sprout C++ Library -// -// Copyright (c) 2013 -// bolero-MURAKAMI : http://d.hatena.ne.jp/boleros/ -// osyo-manga : http://d.hatena.ne.jp/osyo-manga/ -// -// Readme: -// https://github.com/bolero-MURAKAMI/Sprout/blob/master/README -// -// License: -// Boost Software License - Version 1.0 -// -// -#include -#include - -int -main(){ - // - // Random engine - // - static constexpr sprout::default_random_engine engine; - - // - // Distribution - // - // 1 ~ 6 - { - static constexpr sprout::uniform_int_distribution<> dist(1, 6); - static_assert(dist(engine) == 1, ""); - static_assert(dist(engine)() == 1, ""); - static_assert(dist(engine)()() == 5, ""); - static_assert(dist(engine)()()() == 3, ""); - } - - // 0.0 ~ 1.0 - { - static constexpr sprout::uniform_real_distribution dist(0.0, 1.0); -// static_assert(dist(engine) == 0.7.8259e-006, ""); -// static_assert(dist(engine) == 0.131538, ""); -// static_assert(dist(engine) == 0.755605, ""); -// static_assert(dist(engine) == 0.45865, ""); - std::cout << dist(engine) << std::endl; - std::cout << dist(engine)() << std::endl; - std::cout << dist(engine)()() << std::endl; - std::cout << dist(engine)()()() << std::endl; - } - - // Returns true with probability 50% - { - static constexpr sprout::bernoulli_distribution<> dist(0.5); - static_assert(dist(engine) == 1, ""); - static_assert(dist(engine)() == 1, ""); - static_assert(dist(engine)()() == 0, ""); - static_assert(dist(engine)()()() == 1, ""); - } - - return 0; -} +// +// Sprout C++ Library +// +// Copyright (c) 2013 +// bolero-MURAKAMI : http://d.hatena.ne.jp/boleros/ +// osyo-manga : http://d.hatena.ne.jp/osyo-manga/ +// +// Readme: +// https://github.com/bolero-MURAKAMI/Sprout/blob/master/README +// +// License: +// Boost Software License - Version 1.0 +// +// +#include +#include + +int +main(){ + // + // Random engine + // + static constexpr sprout::default_random_engine engine; + + // + // Distribution + // + // 1 ~ 6 + { + static constexpr sprout::uniform_int_distribution<> dist(1, 6); + static_assert(dist(engine) == 1, ""); + static_assert(dist(engine)() == 1, ""); + static_assert(dist(engine)()() == 5, ""); + static_assert(dist(engine)()()() == 3, ""); + } + + // 0.0 ~ 1.0 + { + static constexpr sprout::uniform_real_distribution dist(0.0, 1.0); +// static_assert(dist(engine) == 0.7.8259e-006, ""); +// static_assert(dist(engine) == 0.131538, ""); +// static_assert(dist(engine) == 0.755605, ""); +// static_assert(dist(engine) == 0.45865, ""); + std::cout << dist(engine) << std::endl; + std::cout << dist(engine)() << std::endl; + std::cout << dist(engine)()() << std::endl; + std::cout << dist(engine)()()() << std::endl; + } + + // Returns true with probability 50% + { + static constexpr sprout::bernoulli_distribution<> dist(0.5); + static_assert(dist(engine) == 1, ""); + static_assert(dist(engine)() == 1, ""); + static_assert(dist(engine)()() == 0, ""); + static_assert(dist(engine)()()() == 1, ""); + } + + return 0; +} diff --git a/libs/random/example/random.cpp b/libs/random/example/random.cpp index 1709cb75..e58ced91 100644 --- a/libs/random/example/random.cpp +++ b/libs/random/example/random.cpp @@ -1,53 +1,53 @@ -// -// Sprout C++ Library -// -// Copyright (c) 2013 -// bolero-MURAKAMI : http://d.hatena.ne.jp/boleros/ -// osyo-manga : http://d.hatena.ne.jp/osyo-manga/ -// -// Readme: -// https://github.com/bolero-MURAKAMI/Sprout/blob/master/README -// -// License: -// Boost Software License - Version 1.0 -// -// -#include - -// -// Compile Time Random -// -int -main(){ - // - // Random engine - // - static constexpr sprout::hellekalek1995 engine; - static_assert(engine() == 2110608584, ""); - static_assert(engine()() == 239248507, ""); - - // - // Distribution - // - static constexpr sprout::uniform_int_distribution dist(100, 999); - - // - // Get random value - // - // return int value - static constexpr int n = *dist(engine); - // or - // operator int -// static constexpr int n = dist(engine); - static_assert(n == 984, ""); - - // - // Next random value - // - static_assert(dist(engine)() == 200, ""); - static_assert(dist(engine)()() == 566, ""); - static_assert(dist(engine)()()() == 255, ""); - static_assert(dist(engine)()()()() == 175, ""); - - return 0; -} +// +// Sprout C++ Library +// +// Copyright (c) 2013 +// bolero-MURAKAMI : http://d.hatena.ne.jp/boleros/ +// osyo-manga : http://d.hatena.ne.jp/osyo-manga/ +// +// Readme: +// https://github.com/bolero-MURAKAMI/Sprout/blob/master/README +// +// License: +// Boost Software License - Version 1.0 +// +// +#include + +// +// Compile Time Random +// +int +main(){ + // + // Random engine + // + static constexpr sprout::hellekalek1995 engine; + static_assert(engine() == 2110608584, ""); + static_assert(engine()() == 239248507, ""); + + // + // Distribution + // + static constexpr sprout::uniform_int_distribution dist(100, 999); + + // + // Get random value + // + // return int value + static constexpr int n = *dist(engine); + // or + // operator int +// static constexpr int n = dist(engine); + static_assert(n == 984, ""); + + // + // Next random value + // + static_assert(dist(engine)() == 200, ""); + static_assert(dist(engine)()() == 566, ""); + static_assert(dist(engine)()()() == 255, ""); + static_assert(dist(engine)()()()() == 175, ""); + + return 0; +} diff --git a/libs/random/example/seed.cpp b/libs/random/example/seed.cpp index 41535b7a..1854e64c 100644 --- a/libs/random/example/seed.cpp +++ b/libs/random/example/seed.cpp @@ -1,57 +1,57 @@ -// -// Sprout C++ Library -// -// Copyright (c) 2013 -// bolero-MURAKAMI : http://d.hatena.ne.jp/boleros/ -// osyo-manga : http://d.hatena.ne.jp/osyo-manga/ -// -// Readme: -// https://github.com/bolero-MURAKAMI/Sprout/blob/master/README -// -// License: -// Boost Software License - Version 1.0 -// -// -#include -#include -// #include - -int -main(){ - static constexpr sprout::uniform_int_distribution 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, ""); - } - - // - // Compile time unique seed - // - { - 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; - - // compile time output -// typedef boost::mpl::print>::type unique_seed_type; -// typedef boost::mpl::print>::type engine_type; -// typedef boost::mpl::print>::type dist_type; - } - - return 0; -} +// +// Sprout C++ Library +// +// Copyright (c) 2013 +// bolero-MURAKAMI : http://d.hatena.ne.jp/boleros/ +// osyo-manga : http://d.hatena.ne.jp/osyo-manga/ +// +// Readme: +// https://github.com/bolero-MURAKAMI/Sprout/blob/master/README +// +// License: +// Boost Software License - Version 1.0 +// +// +#include +#include +// #include + +int +main(){ + static constexpr sprout::uniform_int_distribution 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, ""); + } + + // + // Compile time unique seed + // + { + 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; + + // compile time output +// typedef boost::mpl::print>::type unique_seed_type; +// typedef boost::mpl::print>::type engine_type; +// typedef boost::mpl::print>::type dist_type; + } + + return 0; +} diff --git a/sprout/algorithm/fixed/generate.hpp b/sprout/algorithm/fixed/generate.hpp index 69998b4f..a8b105fd 100644 --- a/sprout/algorithm/fixed/generate.hpp +++ b/sprout/algorithm/fixed/generate.hpp @@ -85,7 +85,7 @@ namespace sprout { template inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm::type generate(Generator const& gen) { - return sprout::fixed::generate(sprout::pit()); + return sprout::fixed::generate(sprout::pit(), gen); } } // namespace fixed