Kea 1.5.0
qid_gen.h
Go to the documentation of this file.
1// Copyright (C) 2011-2015 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7// qid_gen defines a generator for query id's
8//
9// We probably want to merge this with the weighted random in the nsas
10// (and other parts where we need randomness, perhaps another thing
11// for a general libutil?)
12
13#ifndef QID_GEN_H
14#define QID_GEN_H
15
16#include <boost/random/mersenne_twister.hpp>
17#include <boost/random/uniform_int.hpp>
18#include <boost/random/variate_generator.hpp>
19
20#include <stdint.h>
21
22namespace isc {
23namespace util {
24namespace random {
25
34public:
38 static QidGenerator& getInstance();
39
48
52 uint16_t generateQid();
53
57 void seed();
58
59private:
60 // "Mersenne Twister: A 623-dimensionally equidistributed
61 // uniform pseudo-random number generator", Makoto Matsumoto and
62 // Takuji Nishimura, ACM Transactions on Modeling and Computer
63 // Simulation: Special Issue on Uniform Random Number Generation,
64 // Vol. 8, No. 1, January 1998, pp. 3-30.
65 //
66 // mt19937 is an implementation of one of the pseudo random
67 // generators described in this paper.
68 boost::mt19937 generator_;
69
70 // For qid's we want a uniform distribution
71 boost::uniform_int<> dist_;
72
73 boost::variate_generator<boost::mt19937&, boost::uniform_int<> > vgen_;
74};
75
76
77} // namespace random
78} // namespace util
79} // namespace isc
80
81#endif // QID_GEN_H
This class generates Qids for outgoing queries.
Definition: qid_gen.h:33
static QidGenerator & getInstance()
Returns the singleton instance of the QidGenerator.
Definition: qid_gen.cc:26
uint16_t generateQid()
Generate a Qid.
Definition: qid_gen.cc:44
QidGenerator()
Default constructor.
Definition: qid_gen.cc:30
void seed()
Seeds the QidGenerator (based on the current time)
Definition: qid_gen.cc:37
Defines the logger used by the top-level component of kea-dhcp-ddns.