Chris@16: /* boost random/variate_generator.hpp header file Chris@16: * Chris@16: * Copyright Jens Maurer 2002 Chris@16: * Copyright Steven Watanabe 2011 Chris@16: * Distributed under the Boost Software License, Version 1.0. (See Chris@16: * accompanying file LICENSE_1_0.txt or copy at Chris@16: * http://www.boost.org/LICENSE_1_0.txt) Chris@16: * Chris@16: * See http://www.boost.org for most recent version including documentation. Chris@16: * Chris@101: * $Id$ Chris@16: * Chris@16: */ Chris@16: Chris@16: #ifndef BOOST_RANDOM_RANDOM_GENERATOR_HPP Chris@16: #define BOOST_RANDOM_RANDOM_GENERATOR_HPP Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: Chris@16: /// \cond hide_private_members Chris@16: Chris@16: namespace random { Chris@16: Chris@16: ///\endcond Chris@16: Chris@16: /** Chris@16: * A random variate generator is used to join a random number Chris@16: * generator together with a random number distribution. Chris@16: * Boost.Random provides a vast choice of \generators as well Chris@16: * as \distributions. Chris@16: * Chris@16: * The argument for the template parameter Engine shall be of Chris@16: * the form U, U&, or U*, where U models a Chris@16: * \uniform_random_number_generator. Then, the member Chris@16: * engine_value_type names U (not the pointer or reference to U). Chris@16: * Chris@16: * Specializations of @c variate_generator satisfy the Chris@16: * requirements of CopyConstructible. They also satisfy the Chris@16: * requirements of Assignable unless the template parameter Chris@16: * Engine is of the form U&. Chris@16: * Chris@16: * The complexity of all functions specified in this section Chris@16: * is constant. No function described in this section except Chris@16: * the constructor throws an exception. Chris@16: */ Chris@16: template Chris@16: class variate_generator Chris@16: { Chris@16: private: Chris@16: typedef boost::random::detail::ptr_helper helper_type; Chris@16: public: Chris@16: typedef typename helper_type::value_type engine_value_type; Chris@16: typedef Engine engine_type; Chris@16: typedef Distribution distribution_type; Chris@16: typedef typename Distribution::result_type result_type; Chris@16: Chris@16: /** Chris@16: * Constructs a @c variate_generator object with the associated Chris@16: * \uniform_random_number_generator eng and the associated Chris@16: * \random_distribution d. Chris@16: * Chris@16: * Throws: If and what the copy constructor of Engine or Chris@16: * Distribution throws. Chris@16: */ Chris@16: variate_generator(Engine e, Distribution d) Chris@16: : _eng(e), _dist(d) { } Chris@16: Chris@16: /** Returns: distribution()(engine()) */ Chris@16: result_type operator()() { return _dist(engine()); } Chris@16: /** Chris@16: * Returns: distribution()(engine(), value). Chris@16: */ Chris@16: template Chris@16: result_type operator()(const T& value) { return _dist(engine(), value); } Chris@16: Chris@16: /** Chris@16: * Returns: A reference to the associated uniform random number generator. Chris@16: */ Chris@16: engine_value_type& engine() { return helper_type::ref(_eng); } Chris@16: /** Chris@16: * Returns: A reference to the associated uniform random number generator. Chris@16: */ Chris@16: const engine_value_type& engine() const { return helper_type::ref(_eng); } Chris@16: Chris@16: /** Returns: A reference to the associated \random_distribution. */ Chris@16: distribution_type& distribution() { return _dist; } Chris@16: /** Chris@16: * Returns: A reference to the associated random distribution. Chris@16: */ Chris@16: const distribution_type& distribution() const { return _dist; } Chris@16: Chris@16: /** Chris@16: * Precondition: distribution().min() is well-formed Chris@16: * Chris@16: * Returns: distribution().min() Chris@16: */ Chris@16: result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (distribution().min)(); } Chris@16: /** Chris@16: * Precondition: distribution().max() is well-formed Chris@16: * Chris@16: * Returns: distribution().max() Chris@16: */ Chris@16: result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (distribution().max)(); } Chris@16: Chris@16: private: Chris@16: Engine _eng; Chris@16: distribution_type _dist; Chris@16: }; Chris@16: Chris@16: } // namespace random Chris@16: Chris@16: using random::variate_generator; Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // BOOST_RANDOM_RANDOM_GENERATOR_HPP