fix(Scripts/TheBotanica): Rework Laj (#15279)

This commit is contained in:
Skjalf
2023-03-05 11:14:46 -03:00
committed by GitHub
parent 5d55449b89
commit a5b4aecd52
3 changed files with 88 additions and 90 deletions

View File

@@ -139,6 +139,21 @@ namespace Acore::Containers
return *it;
}
/*
* Select a random element from a container.
*
* Note: container cannot be empty
*/
template<class C, class Predicate>
inline auto SelectRandomContainerElementIf(C const& container, Predicate&& predicate) -> typename std::add_const<decltype(*std::begin(container))>::type&
{
C containerCopy;
std::copy_if(std::begin(container), std::end(container), std::inserter(containerCopy, std::end(containerCopy)), predicate);
auto it = std::begin(containerCopy);
std::advance(it, urand(0, uint32(std::size(containerCopy)) - 1));
return *it;
}
/*
* Select a random element from a container where each element has a different chance to be selected.
*