How efficient is it to create a temporary uniform random distribution every time per cycle?

For example:

for (...)
{
    ... std::uniform_real_distribution<float>(min, max)(rng) ...
}

Intuitively, it seems to me that the designer does not need to do anything except store two values, and there should be no state in a uniform instance of _ * _. I myself did not profile it (I was not at this stage in the project yet), but I felt that this question was there :)

I know this would be a bad idea for some types of propagation, for example, it std::normal_distributioncan generate its numbers in pairs, and the second number will be wasted every time.

I feel like I have more readability than just access to rng(), and I do the math myself, but I would be wondering if there are other ways to write this more directly.

+4
2

std::uniform_real_distribution , .

, . reset() STL:

void
reset() { }

, std::normal_distribution:

void
reset()
{ _M_saved_available = false; }
+5

, rng , . Mersenne twister - 600 ( ++). , , rng.

, , , rng . .

, , , (, min + (max - min)*x mu + sigma*x ).

0

Source: https://habr.com/ru/post/1625404/


All Articles