16 template <
typename RandomGenerator = std::default_random_engine>
18 RandomGenerator& gen = RandomGenerator())
20 float sum = std::accumulate(map.begin(), map.end(), 0.0);
21 auto dis = std::bernoulli_distribution(sum);
26 template <
typename RandomGenerator>
33 template <
typename Container_w,
typename Container>
34 typename Container::iterator
37 auto dis = std::discrete_distribution<>(weight.begin(), weight.end());
38 auto res = std::next(cont.begin(), dis(
gen_));
42 template <
typename Container_w,
typename Container>
43 typename Container::iterator
46 return select(weight, cont);
55 template <
typename RandomGenerator>
63 template <
typename Iter>
67 = std::uniform_int_distribution<>(0, std::distance(start, end) - 1);
68 std::advance(start, dis(
gen_));
73 template <
typename Iter>
80 template <
typename Container>
81 auto operator()(
const Container& c) -> decltype(*std::begin(c))
83 return *
select(std::begin(c), std::end(c));
87 template <
typename Container>
88 auto pop(Container& c) ->
typename Container::value_type
90 auto i =
select(std::begin(c), std::end(c));
100 template <
typename RandomGenerator>
Container::iterator operator()(Container_w weight, Container cont) const
auto operator()(const Container &c) -> decltype(*std::begin(c))
A randomly selected member of c.
value_impl< detail::weight_tag > weight
discrete_chooser(RandomGenerator &g)
Container::iterator select(Container_w weight, Container cont) const
Random selector on container, using uniform distribution.
Iter operator()(Iter start, Iter end)
A randomly selected iterator in [start, end).
std::mt19937 & make_random_engine()
Generate a unique random device.
auto pop(Container &c) -> typename Container::value_type
A randomly selected member of c. Remove it from c.
random_selector(RandomGenerator &g)
random_selector< RandomGenerator > make_random_selector(RandomGenerator &g)
static bool choose_map(const std::vector< float > &map, RandomGenerator &gen=RandomGenerator())
Choose whether to pick an element from a map or not.
Iter select(Iter start, Iter end)
A randomly selected iterator in [start, end).
Random selector on container, using discrete distribution.