merged paul

This commit is contained in:
2024-07-13 16:14:31 -04:00
20 changed files with 324 additions and 63 deletions

View File

@ -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