]> git.donarmstrong.com Git - rsem.git/blobdiff - boost/random/random_number_generator.hpp
Updated boost to v1.55.0
[rsem.git] / boost / random / random_number_generator.hpp
index 55a945b9e37efc80a5a1e9df79205b52a051343c..f8eaf01bd56ed7eed4b8dc5be5c3da5aba6a3f31 100644 (file)
@@ -7,7 +7,7 @@
  *
  * See http://www.boost.org for most recent version including documentation.
  *
- * $Id: random_number_generator.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
+ * $Id: random_number_generator.hpp 71018 2011-04-05 21:27:52Z steven_watanabe $
  *
  * Revision history
  *  2001-02-18  moved to individual header files
 #ifndef BOOST_RANDOM_RANDOM_NUMBER_GENERATOR_HPP
 #define BOOST_RANDOM_RANDOM_NUMBER_GENERATOR_HPP
 
-#include <boost/config.hpp>
-#include <boost/limits.hpp>
-#include <boost/static_assert.hpp>
-#include <boost/random/uniform_int.hpp>
-#include <boost/random/variate_generator.hpp>
+#include <boost/assert.hpp>
+#include <boost/random/uniform_int_distribution.hpp>
+
+#include <boost/random/detail/disable_warnings.hpp>
 
 namespace boost {
+namespace random {
 
 /**
  * Instantiations of class template random_number_generator model a
@@ -32,40 +32,42 @@ namespace boost {
  *
  * The template parameter IntType shall denote some integer-like value type.
  */
-template<class UniformRandomNumberGenerator, class IntType = long>
+template<class URNG, class IntType = long>
 class random_number_generator
 {
 public:
-  typedef UniformRandomNumberGenerator base_type;
-  typedef IntType argument_type;
-  typedef IntType result_type;
-  /**
-   * Constructs a random_number_generator functor with the given
-   * \uniform_random_number_generator as the underlying source of
-   * random numbers.
-   */
-  random_number_generator(base_type& rng) : _rng(rng)
-  { 
-#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
-    BOOST_STATIC_ASSERT(std::numeric_limits<result_type>::is_integer);
-#endif
-  }
-  // compiler-generated copy ctor is fine
-  // assignment is disallowed because there is a reference member
+    typedef URNG base_type;
+    typedef IntType argument_type;
+    typedef IntType result_type;
+    /**
+     * Constructs a random_number_generator functor with the given
+     * \uniform_random_number_generator as the underlying source of
+     * random numbers.
+     */
+    random_number_generator(base_type& rng) : _rng(rng) {}
+
+    // compiler-generated copy ctor is fine
+    // assignment is disallowed because there is a reference member
 
-  /**
-   * Returns a value in the range [0, n)
-   */
-  result_type operator()(argument_type n)
-  {
-    typedef uniform_int<IntType> dist_type;
-    return variate_generator<base_type&, dist_type>(_rng, dist_type(0, n-1))();
-  }
+    /**
+     * Returns a value in the range [0, n)
+     */
+    result_type operator()(argument_type n)
+    {
+        BOOST_ASSERT(n > 0);
+        return uniform_int_distribution<IntType>(0, n-1)(_rng);
+    }
 
 private:
-  base_type& _rng;
+    base_type& _rng;
 };
 
+} // namespace random
+
+using random::random_number_generator;
+
 } // namespace boost
 
+#include <boost/random/detail/enable_warnings.hpp>
+
 #endif // BOOST_RANDOM_RANDOM_NUMBER_GENERATOR_HPP