It's possible for distributions to cache some state and thereby reduce the frequency of calls to the engine to obtain entropy. For example, the Box-Muller transform maps two samples from a uniform distribution into two samples from a normal distribution. It's possible to implement std::normal_distribution
via Box-Muller so that it makes two calls to the engine for every second call to the distribution.
Ideally you would store an engine and distribution per-thread - or more granular, but certainly not less - and pass a lambda or std::function<int()>
to your function f
to insulate it from the details of how the random numbers are obtained.