OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
random_generator.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
3 //
4 
5 #ifndef BASE_RANDOM_GENERATOR_H_
6 #define BASE_RANDOM_GENERATOR_H_
7 
8 #include <boost/uuid/random_generator.hpp>
9 #include <boost/random/mersenne_twister.hpp>
10 #include <boost/random/uniform_int.hpp>
11 #include <tbb/mutex.h>
12 
14  public:
16  tbb::mutex::scoped_lock lock(mutex_);
17  return rgen_();
18  }
19 
20  private:
21  boost::uuids::random_generator rgen_;
22  tbb::mutex mutex_;
23 };
24 
26  public:
27  UniformInt8RandomGenerator(uint8_t min, uint8_t max) : rgen_(min, max) {}
28 
29  uint8_t operator()() {
30  tbb::mutex::scoped_lock lock(mutex_);
31  return rgen_(rng_);
32  }
33 
34  private:
35  boost::random::mt19937 rng_;
36  boost::random::uniform_int_distribution<uint8_t> rgen_;
37  tbb::mutex mutex_;
38 };
39 
40 #endif // BASE_RANDOM_GENERATOR_H_
boost::random::mt19937 rng_
boost::uuids::uuid uuid
boost::uuids::random_generator rgen_
boost::random::uniform_int_distribution< uint8_t > rgen_
boost::uuids::uuid operator()()
UniformInt8RandomGenerator(uint8_t min, uint8_t max)