Do they all inherit from a base class? Do I have to use templates?
(I am referring to these http://www.codeguru.com/cpp/cpp/cpp_mfc/stl/article.php/c15319/)
I am doing this right now:
typedef std::mt19937 RNG;
and then
class Chooser {
public:
Chooser(RNG& rng, uint n, uint min_choices, uint max_choices):
In other words, I'm passing references to RNG. How would I pass in an arbitrary generator?
Also, I realize this is maybe a different question, but how do I pass the generator to STL?
std::random_shuffle(choices_.begin(), choices_.end(), rng);
doesn't seem to work.
solution to passing generator:
typedef std::ranlux64_base_01 RNG;
typedef std::mt19937 RNGInt;
solution to passing to STL:
struct STL_RNG {
STL_RNG(RNGInt& rng): gen(rng) {}
RNGInt& gen;
int operator()(int n) { return std::uniform_int<int>(0, n)(gen); }
};
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…