Calling reset()
on a distribution object d
has the following effect:
Subsequent uses of d do not depend on values produced by any engine
prior to invoking reset.
(an engine is in short a generator that can be seeded).
In other words, it clears any "cached" random data that the distribution object has stored and that depends on output that it has previously drawn from an engine.
So, if you want to do that then you should call reset()
. The main reason I can think of that you would want to do that is when you are seeding your engine with a known value with the intention of producing repeatable pseudo-random results. If you want the results from your distribution object to also be repeatable based on that seed, then you need to reset the distribution object (or create a new one).
Another reason I can think of is that you are defensively reseeding the generator object because you fear that some attacker may gain partial knowledge of its internal state (as for example Fortuna does). To over-simplify, you can imagine that the quality/security of the generator's data diminishes over time, and that reseeding restores it. Since a distribution object can cache arbitrary amounts of data from the generator, there will be an arbitrary delay between increasing the quality/security of the output of the generator, and increasing the quality/security of the output of the distribution object. Calling reset
on the distribution object avoids this delay. But I won't swear to this latter use being correct, because it gets into the realms where I prefer not to make my own judgement about what is secure, if I can possibly rely on peer-reviewed work by an expert :-)
With regard to your code in particular -- if you don't want the output to depend on previous use of the same dist
object with different generator objects, then calling reset()
would be the way to do that. But I think it's unlikely that calling reset
on a distribution object and then using it with new parameters will be any cheaper than constructing a new distribution object with those parameters. So using a static
local object seems to me to make your function non-thread-safe for no benefit: you could create a new distribution object each time and the code would likely be no worse. There are reasons for the design in the standard, and you're expected to use a distribution object repeatedly with the same generator. The function you've written, cutting the distribution object out of the interface, discards the benefits of that part of the design in the standard.