ExRandom  3.0
rand_table.hpp
Go to the documentation of this file.
1 /**
2  * @file rand_table.hpp
3  * @author Charles Karney <charles.karney@sri.com>
4  * @brief Definition of rand_table
5  *
6  * Copyright (c) Charles Karney (2014) and licensed under the MIT/X11 License.
7  * For more information, see http://exrandom.sourceforge.net/
8  */
9 
10 #if !defined(EXRANDOM_RAND_TABLE_HPP)
11 #define EXRANDOM_RAND_TABLE_HPP 1
12 
14 
15 namespace exrandom {
16 
17  /**
18  * @brief a wrapper to table_gen to make it look like a rand_digit.
19  */
20  class rand_table {
21  public:
22  /**
23  * The base for the digits, 10.
24  */
25  static const uint_t base = 10U;
26  /**
27  * The minimum value produced by operator().
28  */
29  static const uint_t min_value = 0U;
30  /**
31  * The maximum value produced by operator().
32  */
33  static const uint_t max_value = base - 1U;
34  /**
35  * The number of bits needed to represent a digit.
36  */
37  static const int bits = 4;
38  /**
39  * Is the base a power of two?
40  */
41  static const bool power_of_two = false;
42  /**
43  * The constructor (which initializes the count to 0).
44  */
45  rand_table() : _count(0) {};
46  /**
47  * @tparam Generator the type of g.
48  * @param g the random generator engine.
49  * @return the random digit.
50  */
51  template<typename Generator>
52  uint_t operator()(Generator& g)
53  { ++_count; return g(); }
54  /**
55  * @return the count.
56  */
57  long long count() const { return _count; }
58  /**
59  * @tparam the floating point type of the result.
60  * @return 1/@e base as a floating point number.
61  */
62  template<typename RealType>
63  static RealType invrealbase() { return 1/RealType(base); }
64  private:
65  long long _count;
66  };
67 
68 }
69 
70 #endif // EXRANDOM_RAND_TABLE_HPP
static const uint_t max_value
Definition: rand_table.hpp:33
static const uint_t base
Definition: rand_table.hpp:25
Definition of digit_arithmetic.
static const uint_t min_value
Definition: rand_table.hpp:29
a wrapper to table_gen to make it look like a rand_digit.
Definition: rand_table.hpp:20
static RealType invrealbase()
Definition: rand_table.hpp:63
static const int bits
Definition: rand_table.hpp:37
uint_t operator()(Generator &g)
Definition: rand_table.hpp:52
The common namespace.
Definition: aux_info.hpp:18
static const bool power_of_two
Definition: rand_table.hpp:41
long long count() const
Definition: rand_table.hpp:57