Is it possible to use a random engine provided by the STL in C++11 with multiple adaptors?
For example, using the Mersenne Twister Engine with both the Discard Block engine adaptor (from each block of size P generated by the base engine, the adaptor keeps only R numbers, discarding the rest) and the Shuffle Order engine adaptor (delivers the output of a random number engine in different order).
Example engine adaptor use for anyone unaware:
//some code here to create a valid seed sequence
mt19937 eng(mySeedSequence);
discard_block_engine<mt19937,11,5> discardWrapper(eng);
shuffle_order_engine<mt19937,50> shuffleWrapper(eng);
for (int i=0; i<100; ++i) {
//for every 5 calls to "discardWrapper()", the twister engine
//advances by 11 states (6 random numbers are thrown away)
cout << discardWrapper() << endl;
}
for (int i=0; i<100; ++i) {
//essentially 50 random numbers are generated from the Twister
//engine and put into a maintained table, one is then picked from
//the table, not necessarily in the order you would expect if you
//knew the internal state of the engine
cout << shuffleWrapper() << endl;
}
Aucun commentaire:
Enregistrer un commentaire