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