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

Function random_element

include/fplus/transform.hpp:215–222  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

213// Also known as choice.
214template <typename Container>
215typename Container::value_type random_element(
216 std::uint_fast32_t seed, const Container& xs)
217{
218 assert(is_not_empty(xs));
219 std::mt19937 gen(seed);
220 std::uniform_int_distribution<std::size_t> dis(0, size_of_cont(xs) - 1);
221 return elem_at_idx(dis(gen), xs);
222}
223
224// API search type: random_elements : (Int, Int, [a]) -> a
225// fwd bind count: 2

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