Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
template<typename Value>
auto weighted_choice_gen(std::vector<Weighted<Value>> const& weighted_values)
{
auto const& intervals = details::make_intervals(weighted_values);
double sum_weights = intervals.back().first;
return [=](std::mt19937& bit_gen) -> Value
{
std::uniform_real_distribution<double> distribution(0., sum_weights);
return details::search_containing_interval(intervals, distribution(bit_gen));
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment