|
||||
File indexing completed on 2025-01-30 09:59:13
0001 /* boost random/random_number_generator.hpp header file 0002 * 0003 * Copyright Jens Maurer 2000-2001 0004 * Distributed under the Boost Software License, Version 1.0. (See 0005 * accompanying file LICENSE_1_0.txt or copy at 0006 * http://www.boost.org/LICENSE_1_0.txt) 0007 * 0008 * See http://www.boost.org for most recent version including documentation. 0009 * 0010 * $Id$ 0011 * 0012 * Revision history 0013 * 2001-02-18 moved to individual header files 0014 */ 0015 0016 #ifndef BOOST_RANDOM_RANDOM_NUMBER_GENERATOR_HPP 0017 #define BOOST_RANDOM_RANDOM_NUMBER_GENERATOR_HPP 0018 0019 #include <boost/assert.hpp> 0020 #include <boost/random/uniform_int_distribution.hpp> 0021 0022 #include <boost/random/detail/disable_warnings.hpp> 0023 0024 namespace boost { 0025 namespace random { 0026 0027 /** 0028 * Instantiations of class template random_number_generator model a 0029 * RandomNumberGenerator (std:25.2.11 [lib.alg.random.shuffle]). On 0030 * each invocation, it returns a uniformly distributed integer in 0031 * the range [0..n). 0032 * 0033 * The template parameter IntType shall denote some integer-like value type. 0034 */ 0035 template<class URNG, class IntType = long> 0036 class random_number_generator 0037 { 0038 public: 0039 typedef URNG base_type; 0040 typedef IntType argument_type; 0041 typedef IntType result_type; 0042 /** 0043 * Constructs a random_number_generator functor with the given 0044 * \uniform_random_number_generator as the underlying source of 0045 * random numbers. 0046 */ 0047 random_number_generator(base_type& rng) : _rng(rng) {} 0048 0049 // compiler-generated copy ctor is fine 0050 // assignment is disallowed because there is a reference member 0051 0052 /** 0053 * Returns a value in the range [0, n) 0054 */ 0055 result_type operator()(argument_type n) 0056 { 0057 BOOST_ASSERT(n > 0); 0058 return uniform_int_distribution<IntType>(0, n-1)(_rng); 0059 } 0060 0061 private: 0062 base_type& _rng; 0063 }; 0064 0065 } // namespace random 0066 0067 using random::random_number_generator; 0068 0069 } // namespace boost 0070 0071 #include <boost/random/detail/enable_warnings.hpp> 0072 0073 #endif // BOOST_RANDOM_RANDOM_NUMBER_GENERATOR_HPP
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |