#include #include #include int main(void) { unsigned int seed = std::time(NULL); boost::mt19937 eng(seed); // The specific random factory doesn't affect the result. const unsigned long range = (unsigned long) (eng.max() / 5.5); const int num_buckets = 20; // Feel free to change num_buckets. The number 20 isn't important. boost::uniform_int rnd(0, range); std::vector bucket(num_buckets); for (int i = 0; i < 1000000; ++i) ++bucket[rnd(eng) / (range / num_buckets)]; for (int i = 0; i < num_buckets; ++i) std::cout << i << ": " << bucket[i] << '\n'; }