OpenSDN source code
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 <mutex>
9 
10 #include <boost/uuid/random_generator.hpp>
11 #include <boost/random/mersenne_twister.hpp>
12 #include <boost/random/uniform_int.hpp>
13 
15  public:
17  std::scoped_lock lock(mutex_);
18  return rgen_();
19  }
20 
21  private:
22  boost::uuids::random_generator rgen_;
23  std::mutex mutex_;
24 };
25 
27  public:
28  UniformInt8RandomGenerator(uint8_t min, uint8_t max) : rgen_(min, max) {}
29 
30  uint8_t operator()() {
31  std::scoped_lock lock(mutex_);
32  return rgen_(rng_);
33  }
34 
35  private:
36  boost::random::mt19937 rng_;
37  boost::random::uniform_int_distribution<uint8_t> rgen_;
38  std::mutex mutex_;
39 };
40 
41 #endif // BASE_RANDOM_GENERATOR_H_
boost::uuids::random_generator rgen_
boost::uuids::uuid operator()()
UniformInt8RandomGenerator(uint8_t min, uint8_t max)
boost::random::mt19937 rng_
boost::random::uniform_int_distribution< uint8_t > rgen_
boost::uuids::uuid uuid