1 #ifndef VCSN_MISC_RANDOM_HH
2 # define VCSN_MISC_RANDOM_HH
13 template <
typename RandomGenerator = std::default_random_engine>
21 template <
typename Iter>
24 std::uniform_int_distribution<> dis(0, std::distance(start, end) - 1);
25 std::advance(start, dis(
gen_));
30 template <
typename Iter>
37 template <
typename Container>
38 auto operator()(
const Container& c) -> decltype(*std::begin(c))
40 return *
select(std::begin(c), std::end(c));
44 template <
typename Container>
45 auto pop(Container& c) ->
typename Container::value_type
47 auto i =
select(std::begin(c), std::end(c));
58 template <
typename RandomGenerator = std::default_random_engine>
63 template <
typename RandomGenerator>
72 #endif // !VCSN_MISC_RANDOM_HH
struct random_selector< RandomGenerator > make_random_selector(const RandomGenerator &g) ATTRIBUTE_PURE
random_selector(const RandomGenerator &g=RandomGenerator())
auto pop(Container &c) -> typename Container::value_type
A randomly selected member of c. Remove it from c.
Iter operator()(Iter start, Iter end)
A randomly selected iterator in [start, end).
auto operator()(const Container &c) -> decltype(*std::begin(c))
A randomly selected member of c.
Iter select(Iter start, Iter end)
A randomly selected iterator in [start, end).