Is there a function for obtaining uniformly distributed pseudo-random integers in some specified range? I could write my own function using rand, but this seems like a common enough situation that there’s probably something in the STL for it.
Is there a function for obtaining uniformly distributed pseudo-random integers in some specified range?
Share
Boost provides many tools for random number generation.
For uniform distributions you have this one:
http://www.boost.org/doc/libs/1_49_0/doc/html/boost/random/uniform_real_distribution.html
EDIT: updated to include the new C++11 implementation. For the case of integers, here you have the reference:
http://en.cppreference.com/w/cpp/numeric/random/uniform_int_distribution
A simple example would be: