In C ++ 11:
#include <random> std::default_random_engine re; re.seed(time(NULL)); // or whatever seed std::uniform_int_distribution<int> uni(5, 25); // 5-25 *inclusive* int randomNum = uni(re);
Or it could be like this:
std::uniform_int_distribution<int> d5(1, 5);
which would give a different distribution in the same range.
Steve jessop
source share