6 #include "boost/random.hpp"
11 simul(unsigned int seed) : engine(seed), rg(engine, boost::random::uniform_01<>()) {
15 // random number should be in [0, arr[len - 1])
16 // If by chance arr[len - 1] == 0.0, one possibility is to sample uniformly from 0 ... len - 1
17 int sample(double* arr, int len) {
19 double prb = random() * arr[len - 1];
25 if (arr[mid] <= prb) l = mid + 1;
29 if (l >= len) { printf("%d %lf %lf\n", len, arr[len - 1], prb); }
35 double random() { return rg(); };
38 boost::random::mt19937 engine;
39 boost::random::variate_generator<boost::random::mt19937&, boost::random::uniform_01<> > rg;