是否可以在C++11中同时使用STL提供的随机引擎和多个适配器?
例如,使用Mersenne Twister引擎与Discard Block engine adaptor(从每个大小为P的块生成的基础引擎中,适配器仅保留R个数字,丢弃其余数字)和Shuffle Order engine adaptor(以不同顺序提供随机数引擎的输出)。
以下是适配器的示例用法,以防您不熟悉:
//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;
}