I can use:
boost::mt19937 gen(43);
this works fine, but what if I want more than a 32-bit seed before using the random number generator? Is there an easy way to put 64-bit or 128-bit seed in a Mersenne Twister?
I found some examples of loading multiple values before generating the results, but none of them work.
There are several problems with this code:
std::vector<unsigned int> seedv(1000, 11); std::vector<unsigned int>::iterator i=seedv.begin(); boost::mt19937 gen2(i, seedv.end());
First, calling gen2 () always returns the same value. I don’t know how I ruined it.
Secondly, I do not want 1000 seeds, but when I lower it to 600, it "throws an instance of std :: invalid_argument with enough notes in the call for the seed"
Can this method be reduced to a few seeds?
Here is another sample code that looks easy:
std::string seedv("thisistheseed"); std::seed_seq q(seedv.begin(),seedv.end()); boost::mt19937 gen2(q);
but it will not compile. I finally realized that std :: seed_seq is only available in C ++ 11. I was stuck with gcc 4.7 as long as the libraries I depend on are stable.
I suppose I can just stick to the 32 bit seed, but I wanted a little more.
I read this article: Boost Mersenne Twister: how to sow more than one value?
I like the idea of initializing the entire vector from:
mersenne_twister(seed1) ^ mersenne_twister(seed2)
but I see no way to do this without changing Mersenne_Twister.hpp
Any suggestions?
UPDATE: another way not to do this!
unsigned long seedv[4]; seedv[0]=1; seedv[1]=2; seedv[2]=3; seedv[3]=4; boost::mt19937 gen2(seedv,4);
With proper casting, this should work, but every cast that I tried will still not pass the compiler. I can draw something in C, but C ++ still drinks me ...