merged paul
This commit is contained in:
19
src/rng.h
19
src/rng.h
@ -33,9 +33,24 @@ public:
|
||||
int exclude_middle(const int lower_bound, const int upper_bound,
|
||||
const int excluded);
|
||||
|
||||
template<class T> T rand_exclude(std::vector<T> &vec, T &target);
|
||||
template<class T> T rand_exclude(std::vector<T> &vec, T &target) {
|
||||
std::size_t idx = 0;
|
||||
|
||||
template<class T> T get_rand_in_vector(std::vector<T> &vec);
|
||||
for (; idx < vec.size(); ++idx)
|
||||
if (vec[idx] == target)
|
||||
break;
|
||||
|
||||
return vec[exclude_middle(0, vec.size(), idx)];
|
||||
}
|
||||
|
||||
template<class T> T get_rand_in_vector(std::vector<T> &vec) {
|
||||
if (!vec.size())
|
||||
return T{};
|
||||
|
||||
curr_rand_num = rand();
|
||||
|
||||
return vec[curr_rand_num % vec.size()];
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user