9 #include "boost/random.hpp"
11 boost::mt19937 rng(time(NULL));
12 boost::uniform_01<boost::mt19937> rg(rng);
14 // arr should be cumulative!
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(std::vector<double>& arr, int len) {
20 double prb = rg() * 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); }