C++11 random engine and engine adapters with predefined parameters -predefined engine
C++11 has introduced many features in C++ and random engine is one of them,here we will see the C++11 random engine and engines adapters with predefined parameters.Those engine whose parameters are predefined are known as predefined engine.
There are some engines whose parameters value are predefined or fixed,they are also known as predefined engine.And in every engine the generation of random number sequence is dependent on their parameters,in predefined random-number engine since the parameters are fixed the generation of the random sequence is dependent only on the state of the engine.This impose restriction to some extend on how you can implement the engine.
The list of all the predefined engines are given below.If you want to know about the difference between random engine and predefined engine visit the link :difference between random engine and predefined engine.
‘minstd_rand0’ C++11 predefined engine
‘minstd_rand0’ is a predefined engine of linear_congruential_engine it is defined as.
typedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647> minstd_rand0;
The 1000th consecutive call of the default constructed minstd_rand0 object will render the value 1043618065.
‘minstd_rand’ C++11 predefined engine
‘minstd_rand’ is also a predefined engine of linear_congruential_engine it is defined as.
typedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647> minstd_rand;
The 1000th consecutive call of the default constructed minstd_rand object will render the value 399268537.
‘mt19937’ C++11 predefined engine
‘mt19937’ is a predefined engine of mersenne_twister_engine it is defined as.
typedef mersenne_twister_engine<uint_fast32_t , 32,624,397 , 31 ,0x9908b0df , 11 , 0xffffffff , 7 , 0x9d2c5680 , 15 , 0xefc60000 , 18 , 1812433253> mt19937;
The 1000th consecutive call of the default constructed mt19937 object will render the value 4123659995.
‘mt19937_64’ C++11 predefined engine
‘mt19937_64’ is a predefined engine of mersenne_twister_engine it is defined as.
typedef mersenne_twister_engine<uint_fast64_t, 64,312,156,31,0xb5026f5aa96619e9,29, 0x5555555555555555,17, 0x71d67fffeda60000,37, 0xfff7eee000000000,43, 6364136223846793005> mt19937_64;
The 1000th consecutive call of the default constructed mt19937_64 object will render the value 9981545732273789042.
‘ranlux24_base’ C++11 predefined engine
‘ranlux24_base’ is a predefined engine of subtract_with_carry_engine it is defined as.
typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24> ranlux24_base;
The 1000th consecutive call of the default constructed ranlux24_base object will render the value 9981545732273789042.
‘ranlux48_base’ C++11 predefined engine
‘ranlux48_base’ is a predefined engine of subtract_with_carry_engine it is defined as.
typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12> ranlux48_base;
The 1000th consecutive call of the default constructed ranlux48_base object will render the value 61839128582725.
‘ranlux24’ C++11 predefined engine
‘ranlux24’ is a predefined engine of discard_block_engine it is defined as.
typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24;
The 1000th consecutive call of the default constructed ranlux24 object will render the value 9901578.
‘ranlux48’ C++11 predefined engine
‘ranlux48’ is a predefined engine of discard_block_engine it is defined as.
typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48;
The 1000th consecutive call of the default constructed ranlux48 object will render the value 249142670248501.
‘knuth_b’ C++11 predefined engine
‘knuth_b’ is a predefined engine of shuffle_order_engine it is defined as.
typedef shuffle_order_engine<minstd_rand0,256> knuth_b;
The 1000th consecutive call of the default constructed knuth_b object will render the value 1112339016.
‘default_random_engine’
default_random_engine is an implementation-specific engine,it is defined as
typedef implementation-defined default_random_engine;
The implementation-defined means the engine selected is different on different compiler.The engine selected may be based on performance, size, quality, or any combination of such factors.Since the implementation may select different engine the random sequence generated by the default_random_engine in different compiler will be different.
default_random_engine dre; for(auto i=0 ;i <3 ;i++) { cout<< dre() << ” ” }
Output in code::blocks,
Output in Visual Studio,