-
Notifications
You must be signed in to change notification settings - Fork 0
/
PairGenerator.h
59 lines (44 loc) · 1.21 KB
/
PairGenerator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* PairGenerator.h
*
* Created on: Aug 5, 2012
* Author: jvlek
*/
#ifndef PAIRGENERATOR_H_
#define PAIRGENERATOR_H_
#include <utility>
#include <vector>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_01.hpp>
#include <boost/random/variate_generator.hpp>
typedef boost::variate_generator<boost::mt19937&, boost::uniform_01<> > RandomGenerator;
class PairGenerator
{
public:
PairGenerator();
virtual ~PairGenerator();
template <typename T>
std::pair<T, T> removeRandomPair(std::vector<T>& singles);
private:
boost::mt19937 m_rawGenerator;
RandomGenerator* m_generator;
template<typename T>
T removeRandomSingle(std::vector<T>& singles);
};
template<typename T>
std::pair<T, T> PairGenerator::removeRandomPair(std::vector<T>& singles)
{
T first = removeRandomSingle(singles);
T second = removeRandomSingle(singles);
return std::pair<T, T>(first, second);
}
template<typename T>
T PairGenerator::removeRandomSingle(std::vector<T>& singles)
{
unsigned int index = (unsigned int) singles.size() * (*m_generator)();
typename std::vector<T>::iterator iter = singles.begin() + index;
T single = *(iter);
singles.erase(iter);
return single;
}
#endif /* PAIRGENERATOR_H_ */