X-Git-Url: https://git.donarmstrong.com/?p=rsem.git;a=blobdiff_plain;f=sampling.h;h=88200909d4b6e8bf13854808fa72f835ce20cdcb;hp=417140395b8b78801af1808fc93bf6d3eca9d602;hb=683863b75f8d8bef2461039a6911b0e9619cc113;hpb=1c7a81621434a852a7f7e11d61621e50ba1b7f2a diff --git a/sampling.h b/sampling.h index 4171403..8820090 100644 --- a/sampling.h +++ b/sampling.h @@ -5,17 +5,39 @@ #include #include #include +#include #include "boost/random.hpp" -boost::mt19937 rng(time(NULL)); -boost::uniform_01 rg(rng); +typedef unsigned int seedType; +typedef boost::mt19937 engine_type; +typedef boost::gamma_distribution<> gamma_dist; +typedef boost::uniform_01 uniform01; +typedef boost::variate_generator gamma_generator; + +class engineFactory { +public: + static engine_type *new_engine() { + seedType seed; + static engine_type seedEngine(time(NULL)); + static std::set seedSet; // empty set of seeds + std::set::iterator iter; + + do { + seed = seedEngine(); + iter = seedSet.find(seed); + } while (iter != seedSet.end()); + seedSet.insert(seed); + + return new engine_type(seed); + } +}; // arr should be cumulative! // interval : [,) // random number should be in [0, arr[len - 1]) // If by chance arr[len - 1] == 0.0, one possibility is to sample uniformly from 0...len-1 -int sample(std::vector& arr, int len) { +int sample(uniform01& rg, std::vector& arr, int len) { int l, r, mid; double prb = rg() * arr[len - 1];