The function is the following:
float random_float(float min, float max)
{
std::random_device rd; // obtain a random number from hardware
std::mt19937 gen(rd()); // seed the generator
std::uniform_real_distribution<> distr((double)min, (double)max); // define the range
return (float)distr(gen);
}
I would like to avoid calling the first 3 lines every time I call this function. I also would rather not create a class with a constructor, then having to instantiate it every time I just want to generate a random number. I'm not very familiar with what is possible with modern C++ features, so I would like some ideas.