MCPcopy Create free account
hub / github.com/Dobiasd/FunctionalPlus / random_elements

Function random_elements

include/fplus/transform.hpp:231–241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

229// Example call: random_elements(std::random_device()(), 10, xs)
230template <typename Container>
231Container random_elements(
232 std::uint_fast32_t seed, std::size_t n, const Container& xs)
233{
234 assert(is_not_empty(xs));
235 std::mt19937 gen(seed);
236 std::uniform_int_distribution<std::size_t> dis(0, size_of_cont(xs) - 1);
237 const auto draw = [&]() -> typename Container::value_type {
238 return elem_at_idx(dis(gen), xs);
239 };
240 return generate<Container>(draw, n);
241}
242
243// API search type: apply_functions : ([(a -> b)], a) -> [b]
244// fwd bind count: 1

Callers 1

transform_test.cppFile · 0.50

Calls 3

is_not_emptyFunction · 0.70
size_of_contFunction · 0.70
elem_at_idxFunction · 0.70

Tested by

no test coverage detected