I'm a beginner in C++, and I just reached some of the new C++11 things, in this case random numbers from "random".
I wrote a simple function that takes to integers, start and end. These integers obviously mark the start and the end of the closed interval in which the random numbers should be.
The function:
int randomInt(int start, int end)
{
using std::default_random_engine;
using std::uniform_int_distribution;
using std::random_device;
random_device rd;
default_random_engine engine(rd());
uniform_int_distribution<int> dist{ start, end };
auto res = dist(engine);
return res;
}
When I execute this piece of code in the main function without using the function, the program works fine and outputs a random number. But when I call the function with a start and an end, the program crashes with the exception "Illegal instruction", and points me to line 3420 in "xutility". Note: the code compiles, the crash occurs only when running.
I am using Visual Studio 2015 Preview with CTP 4.
Aucun commentaire:
Enregistrer un commentaire