Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:51:13

0001 /* boost random/uniform_int.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-04-08  added min<max assertion (N. Becker)
0014  *  2001-02-18  moved to individual header files
0015  */
0016 
0017 #ifndef BOOST_RANDOM_UNIFORM_INT_HPP
0018 #define BOOST_RANDOM_UNIFORM_INT_HPP
0019 
0020 #include <boost/assert.hpp>
0021 #include <boost/random/uniform_int_distribution.hpp>
0022 
0023 namespace boost {
0024 
0025 /**
0026  * The distribution function uniform_int models a \random_distribution.
0027  * On each invocation, it returns a random integer value uniformly
0028  * distributed in the set of integer numbers {min, min+1, min+2, ..., max}.
0029  *
0030  * The template parameter IntType shall denote an integer-like value type.
0031  *
0032  * This class is deprecated.  Please use @c uniform_int_distribution in
0033  * new code.
0034  */
0035 template<class IntType = int>
0036 class uniform_int : public random::uniform_int_distribution<IntType>
0037 {
0038     typedef random::uniform_int_distribution<IntType> base_type;
0039 public:
0040 
0041     class param_type : public base_type::param_type
0042     {
0043     public:
0044         typedef uniform_int distribution_type;
0045         /**
0046          * Constructs the parameters of a uniform_int distribution.
0047          *
0048          * Requires: min <= max
0049          */
0050         explicit param_type(IntType min_arg = 0, IntType max_arg = 9)
0051           : base_type::param_type(min_arg, max_arg)
0052         {}
0053     };
0054 
0055     /**
0056      * Constructs a uniform_int object. @c min and @c max are
0057      * the parameters of the distribution.
0058      *
0059      * Requires: min <= max
0060      */
0061     explicit uniform_int(IntType min_arg = 0, IntType max_arg = 9)
0062       : base_type(min_arg, max_arg)
0063     {}
0064 
0065     /** Constructs a uniform_int distribution from its parameters. */
0066     explicit uniform_int(const param_type& parm)
0067       : base_type(parm)
0068     {}
0069 
0070     /** Returns the parameters of the distribution */
0071     param_type param() const { return param_type(this->a(), this->b()); }
0072     /** Sets the parameters of the distribution. */
0073     void param(const param_type& parm) { this->base_type::param(parm); }
0074 
0075     // Codergear seems to have trouble with a using declaration here
0076 
0077     template<class Engine>
0078     IntType operator()(Engine& eng) const
0079     {
0080         return static_cast<const base_type&>(*this)(eng);
0081     }
0082 
0083     template<class Engine>
0084     IntType operator()(Engine& eng, const param_type& parm) const
0085     {
0086         return static_cast<const base_type&>(*this)(eng, parm);
0087     }
0088 
0089     template<class Engine>
0090     IntType operator()(Engine& eng, IntType n) const
0091     {
0092         BOOST_ASSERT(n > 0);
0093         return static_cast<const base_type&>(*this)(eng, param_type(0, n - 1));
0094     }
0095 };
0096 
0097 } // namespace boost
0098 
0099 #endif // BOOST_RANDOM_UNIFORM_INT_HPP