I'm trying to learn C++11 random stuff, so I've copied an example from this site found here on stackoverflow...
What I want to achive here is using a std::xor_combine template to combine two engines and initilize it with 3th engine. according to link abowe this should be possible but it looks that some things are changed here since Tr1 report?
Also you'll se a exponential distrubution object bellow in the code, So one more question is how do I combine xor_combine lobject with distribution so that I pass the "combin" into distributions operator() ?
Visual studio gives me an error described in the code bellow...
#include<iostream>
#include<random>
#include<ctime>
using namespace std;
int main()
{
minstd_rand gen1;
mt19937 gen2;
linear_congruential_engine<unsigned long, 34999, 0, 3405989> seeder;
seeder.seed(static_cast<unsigned long>(time(false)));
xor_combine<minstd_rand, 4, mt19937, 9> combin;
exponential_distribution<float> expdist(2);
combin.seed(seeder);
// generate numbers
for(int i = 0; i < 10; ++i) // error in <random>
cout << combin() << endl; // ERROR C:2039 generate is not a member of std::congruential_engine<...> etc...
cin.get();
return 0;
}
1. How do I pass 3th engine into xor_combine object?
2. How do I pas xor_combine object into distribution object? *EDIT*
#include<iostream>
#include<random>
#include<ctime>
int main()
{
std::minstd_rand gen1;
std::mt19937 gen2;
std::xor_combine<std::minstd_rand, 3, std::mt19937, 6> combin(gen1, gen2);
std::uniform_int_distribution<unsigned int> dist(0,37);
combin.seed(static_cast<unsigned int>(time(0)));
std::cout << dist( combin ) << std::endl;
std::cin.get();
return 0;
}
Error 1 error C2352: 'std::xor_combine<_Engine1,_S1,_Engine2,_S2>::max' : illegal call of non-static member function c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility 3455 Project1 1