/* boost random_test.cpp various tests * * Copyright Matthias Troyer 2006 * Distributed under the Boost Software License, Version 1.0. (See * accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) * * $Id$ */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include void simulate_gauss_impl(boost::buffered_generator& gen) { double sum=0; for (int i=0;i<100000;i++) sum += gen(); std::cout << "The sum of Gaussians is " << sum << "\n"; } void simulate_impl(boost::buffered_uniform_01& gen) { double sum=0; for (int i=0;i<100000;i++) sum += gen(); typedef boost::variate_generator&,boost::normal_distribution<> > gen_type; gen_type gauss(gen,boost::normal_distribution<>()); for (int i=0;i<100000;i++) sum += gauss(); std::cout << "The sum of Uniforms and Gaussians is " << sum << "\n"; } template void simulate_gauss() { typedef boost::variate_generator > gen_type; RNG engine; boost::basic_buffered_generator gen(gen_type(engine,boost::normal_distribution<>())); simulate_gauss_impl(gen); } template void simulate() { boost::basic_buffered_uniform_01 gen; simulate_impl(gen); } template void test(const std::string & name, const PRNG &) { using namespace boost::random; std::cout << "Testing " << name << ": "; PRNG rng; // default ctor simulate(); simulate_gauss(); } void test_all() { test("well512a", boost::well512a()); test("lcg64a", boost::lcg64a()); } int test_main(int, char*[]) { test_all(); return 0; }