Last active
April 29, 2017 11:38
-
-
Save deque-blog/b193e80e754ad9c888fca8e6cff26b65 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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