If you do not need statistical control over the flows, just use the facilities provided by <random>
:
#include <random> typedef std:::mt19937 rng_type; std::uniform_int_distribution<rng_type::result_type> udist(0, 200); int main() // this can be per thread! { rng_type rng; // seed rng first: rng_type::result_type const seedval = get_seed(); rng.seed(seedval); rng_type::result_type random_number = udist(rng); return random_number; }
Mersenne twister PRNG is fast and has good statistical properties. Maintaining a separate (and separately spent) engine object in each thread, you avoid all concurrency problems.
source share