我正在使用Boost随机库为蒙特卡罗模拟生成随机数.为了检查我的结果,我希望能够为不同的运行使用不同的RNG引擎.理想情况下,我想使用命令行选项来确定在运行时使用哪个RNG,而不是例如在编译时通过typedef选择RNG.
是否有基类T,以便可能出现以下内容:或者如果没有,明显的原因不是吗?
#include <boost/random.hpp>
int main()
{
unsigned char rng_choice = 0;
T* rng_ptr; // base_class pointer can point to any RNG from boost::random
switch(rng_choice)
{
case 0:
rng_ptr = new boost::random::mt19937;
break;
case 1:
rng_ptr = new boost::random::lagged_fibonacci607;
break;
}
boost::random::uniform_int_distribution<> dice_roll(1,6);
// Generate a variate from dice_roll using the engine defined by rng_ptr:
dice_roll(*rng_ptr);
delete rng_ptr;
return 0;
}
Run Code Online (Sandbox Code Playgroud)