]> git.donarmstrong.com Git - rsem.git/blob - boost/random/random_number_generator.hpp
RSEM Source Codes
[rsem.git] / boost / random / random_number_generator.hpp
1 /* boost random/random_number_generator.hpp header file
2  *
3  * Copyright Jens Maurer 2000-2001
4  * Distributed under the Boost Software License, Version 1.0. (See
5  * accompanying file LICENSE_1_0.txt or copy at
6  * http://www.boost.org/LICENSE_1_0.txt)
7  *
8  * See http://www.boost.org for most recent version including documentation.
9  *
10  * $Id: random_number_generator.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
11  *
12  * Revision history
13  *  2001-02-18  moved to individual header files
14  */
15
16 #ifndef BOOST_RANDOM_RANDOM_NUMBER_GENERATOR_HPP
17 #define BOOST_RANDOM_RANDOM_NUMBER_GENERATOR_HPP
18
19 #include <boost/config.hpp>
20 #include <boost/limits.hpp>
21 #include <boost/static_assert.hpp>
22 #include <boost/random/uniform_int.hpp>
23 #include <boost/random/variate_generator.hpp>
24
25 namespace boost {
26
27 /**
28  * Instantiations of class template random_number_generator model a
29  * RandomNumberGenerator (std:25.2.11 [lib.alg.random.shuffle]). On
30  * each invocation, it returns a uniformly distributed integer in
31  * the range [0..n).
32  *
33  * The template parameter IntType shall denote some integer-like value type.
34  */
35 template<class UniformRandomNumberGenerator, class IntType = long>
36 class random_number_generator
37 {
38 public:
39   typedef UniformRandomNumberGenerator base_type;
40   typedef IntType argument_type;
41   typedef IntType result_type;
42   /**
43    * Constructs a random_number_generator functor with the given
44    * \uniform_random_number_generator as the underlying source of
45    * random numbers.
46    */
47   random_number_generator(base_type& rng) : _rng(rng)
48   { 
49 #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
50     BOOST_STATIC_ASSERT(std::numeric_limits<result_type>::is_integer);
51 #endif
52   }
53   // compiler-generated copy ctor is fine
54   // assignment is disallowed because there is a reference member
55
56   /**
57    * Returns a value in the range [0, n)
58    */
59   result_type operator()(argument_type n)
60   {
61     typedef uniform_int<IntType> dist_type;
62     return variate_generator<base_type&, dist_type>(_rng, dist_type(0, n-1))();
63   }
64
65 private:
66   base_type& _rng;
67 };
68
69 } // namespace boost
70
71 #endif // BOOST_RANDOM_RANDOM_NUMBER_GENERATOR_HPP