1
是否有可能使用C++ 11中的STL提供的隨機引擎與多個適配器同時使用?C++ 11多個隨機數引擎適配器
例如,使用梅森倍捻機引擎與兩個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;
}
您的意思是說如果可以改編自適應引擎嗎?或者,如果可以通過兩種不同的方式調整相同的底層引擎輸出? –
本質上也是。要同時具有2個適配器的引擎。 –