7 #include "boost/random.hpp"
12 simul() : rg(boost::mt19937(time(NULL))) {
16 // random number should be in [0, arr[len - 1])
17 // If by chance arr[len - 1] == 0.0, one possibility is to sample uniformly from 0 ... len - 1
18 int sample(double* arr, int len) {
20 double prb = random() * arr[len - 1];
26 if (arr[mid] <= prb) l = mid + 1;
30 if (l >= len) { printf("%d %lf %lf\n", len, arr[len - 1], prb); }
36 double random() { return rg(); };
39 boost::uniform_01<boost::mt19937> rg;