34 static Rnd* initRand();
36 static void destroy();
38 void set_seed(
int new_seed);
42 int rnd_int(
int lowerLimit,
int upperLimit );
44 float rnd_flt(
float min=0.0,
float max=1.0);
46 float rnd_dbl(
float min=0.0,
float max=1.0);
48 float operator()(
unsigned i);
52 template <
class RandomAccessIterator>
54 RandomAccessIterator
last)
56 for (
auto i=(
last-first)-1;
i>0; --
i)
58 std::uniform_int_distribution<decltype(
i)> d(0,
i);
63 template<
typename Iter>
66 std::uniform_int_distribution<> dis(0,
67 distance(start, end) - 1);
79 " attemping to return random choice from empty vector");
80 return *select_randomly(v.begin(),v.end());
84 template<
typename T,
typename D>
95 "w.size() = 0 and v.size() = 0");
100 "; Calling random_choice(v)");
102 return random_choice(v);
105 if(w.size() != v.size())
107 cout<<
"WARN! random_choice() w.size() " << w.size() <<
"!= v.size() "
108 << v.size() <<
", Calling random_choice(v)\n";
109 return random_choice(v);
113 assert(v.size() == w.size());
114 std::discrete_distribution<size_t> dis(w.begin(), w.end());
127 vector<std::mt19937>
rg;
135 static Rnd &
r = *Rnd::initRand();
Defines a multi-core random number generator and its operators.
T random_choice(const vector< T > &v)
vector< std::mt19937 > rg
T random_choice(const vector< T > &v, const vector< D > &w)
void shuffle(RandomAccessIterator first, RandomAccessIterator last)
Iter select_randomly(Iter start, Iter end)
#define THROW_LENGTH_ERROR(err)
#define omp_get_thread_num()
std::string to_string(const T &value)
template function to convert objects to string for logging