Chris@16: /* boost random/random_number_generator.hpp header file Chris@16: * Chris@16: * Copyright Jens Maurer 2000-2001 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: * Revision history Chris@16: * 2001-02-18 moved to individual header files Chris@16: */ Chris@16: Chris@16: #ifndef BOOST_RANDOM_RANDOM_NUMBER_GENERATOR_HPP Chris@16: #define BOOST_RANDOM_RANDOM_NUMBER_GENERATOR_HPP Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace random { Chris@16: Chris@16: /** Chris@16: * Instantiations of class template random_number_generator model a Chris@16: * RandomNumberGenerator (std:25.2.11 [lib.alg.random.shuffle]). On Chris@16: * each invocation, it returns a uniformly distributed integer in Chris@16: * the range [0..n). Chris@16: * Chris@16: * The template parameter IntType shall denote some integer-like value type. Chris@16: */ Chris@16: template Chris@16: class random_number_generator Chris@16: { Chris@16: public: Chris@16: typedef URNG base_type; Chris@16: typedef IntType argument_type; Chris@16: typedef IntType result_type; Chris@16: /** Chris@16: * Constructs a random_number_generator functor with the given Chris@16: * \uniform_random_number_generator as the underlying source of Chris@16: * random numbers. Chris@16: */ Chris@16: random_number_generator(base_type& rng) : _rng(rng) {} Chris@16: Chris@16: // compiler-generated copy ctor is fine Chris@16: // assignment is disallowed because there is a reference member Chris@16: Chris@16: /** Chris@16: * Returns a value in the range [0, n) Chris@16: */ Chris@16: result_type operator()(argument_type n) Chris@16: { Chris@16: BOOST_ASSERT(n > 0); Chris@16: return uniform_int_distribution(0, n-1)(_rng); Chris@16: } Chris@16: Chris@16: private: Chris@16: base_type& _rng; Chris@16: }; Chris@16: Chris@16: } // namespace random Chris@16: Chris@16: using random::random_number_generator; Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // BOOST_RANDOM_RANDOM_NUMBER_GENERATOR_HPP