We can use std::uniform_int_distribution
to generate random numbers in a specific interval. However, for my simulation I need a uniformly distributed random integer at each iteration, and the interval is dependent on the outcome of the previous iteration. I'm already aware of some of the tricks (like these) that can be used to produce a uniform / near-uniform distribution of integers from a larger interval, but is there a standard or recommended "post-c++11ish" way to do this?
I know it's possible to just create a new uniform_int_distribution
object at each iteration. Are there any hidden caveats or gotchas to this approach? It seems that distribution objects do hold some internal state, so I'm slightly concerned that using a fresh distribution object to generate a single random number might have some drawbacks or undesirable characteristics that are not obvious to me.