I am probably doing more effort than necessary but who cares, let's try to solve this problem:
I would like to use the "random_device" generator from <random>
in my code. But that might not be available on some systems (according to specs), so I would like to have mt19937 as a backup (but whatever generator I use, I would like to have the same variable name at the end). Now, I can try the random_device to see if it is working, but what then? If I use an if statement, my generator will vanish after the if. If I declare it, I cannot change the type afterwards. Below the code, that does not work.
bool random_working=true;
try
{
random_device rd; //throws exception when not able to construct
}
catch(exception& e)
{
cout<<"Exception: ''random_device'' not working, switching back to mt19937"<<endl;
random_working=false;
}
if(random_working)
random_device mc; //for _M_onte-_C_arlo
else
mt19937 mc;