PageRenderTime 25ms CodeModel.GetById 18ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/random/uniform_int.hpp

http://hadesmem.googlecode.com/
C++ Header | 99 lines | 45 code | 14 blank | 40 comment | 0 complexity | e4946892463762030c538a5a58d30377 MD5 | raw file
 1/* boost random/uniform_int.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: uniform_int.hpp 71018 2011-04-05 21:27:52Z steven_watanabe $
11 *
12 * Revision history
13 *  2001-04-08  added min<max assertion (N. Becker)
14 *  2001-02-18  moved to individual header files
15 */
16
17#ifndef BOOST_RANDOM_UNIFORM_INT_HPP
18#define BOOST_RANDOM_UNIFORM_INT_HPP
19
20#include <boost/assert.hpp>
21#include <boost/random/uniform_int_distribution.hpp>
22
23namespace boost {
24
25/**
26 * The distribution function uniform_int models a \random_distribution.
27 * On each invocation, it returns a random integer value uniformly
28 * distributed in the set of integer numbers {min, min+1, min+2, ..., max}.
29 *
30 * The template parameter IntType shall denote an integer-like value type.
31 *
32 * This class is deprecated.  Please use @c uniform_int_distribution in
33 * new code.
34 */
35template<class IntType = int>
36class uniform_int : public random::uniform_int_distribution<IntType>
37{
38    typedef random::uniform_int_distribution<IntType> base_type;
39public:
40
41    class param_type : public base_type::param_type
42    {
43    public:
44        typedef uniform_int distribution_type;
45        /**
46         * Constructs the parameters of a uniform_int distribution.
47         *
48         * Requires: min <= max
49         */
50        explicit param_type(IntType min_arg = 0, IntType max_arg = 9)
51          : base_type::param_type(min_arg, max_arg)
52        {}
53    };
54
55    /**
56     * Constructs a uniform_int object. @c min and @c max are
57     * the parameters of the distribution.
58     *
59     * Requires: min <= max
60     */
61    explicit uniform_int(IntType min_arg = 0, IntType max_arg = 9)
62      : base_type(min_arg, max_arg)
63    {}
64
65    /** Constructs a uniform_int distribution from its parameters. */
66    explicit uniform_int(const param_type& parm)
67      : base_type(parm)
68    {}
69
70    /** Returns the parameters of the distribution */
71    param_type param() const { return param_type(this->a(), this->b()); }
72    /** Sets the parameters of the distribution. */
73    void param(const param_type& parm) { this->base_type::param(parm); }
74
75    // Codergear seems to have trouble with a using declaration here
76
77    template<class Engine>
78    IntType operator()(Engine& eng) const
79    {
80        return static_cast<const base_type&>(*this)(eng);
81    }
82
83    template<class Engine>
84    IntType operator()(Engine& eng, const param_type& parm) const
85    {
86        return static_cast<const base_type&>(*this)(eng, parm);
87    }
88
89    template<class Engine>
90    IntType operator()(Engine& eng, IntType n) const
91    {
92        BOOST_ASSERT(n > 0);
93        return static_cast<const base_type&>(*this)(eng, param_type(0, n - 1));
94    }
95};
96
97} // namespace boost
98
99#endif // BOOST_RANDOM_UNIFORM_INT_HPP