#ifndef PYTHONIC_RANDOM_SAMPLE_HPP #define PYTHONIC_RANDOM_SAMPLE_HPP #include "pythonic/include/random/sample.hpp" #include "pythonic/utils/functor.hpp" #include "pythonic/random/random.hpp" #include "pythonic/types/list.hpp" PYTHONIC_NS_BEGIN namespace random { template types::list::type>:: type::iterator>::value_type> sample(Iterable &&s, size_t k) { using value_type = typename std::iterator_traits::type>::type::iterator>:: value_type; types::list tmp(s.begin(), s.end()); std::vector indices(tmp.size()); std::iota(indices.begin(), indices.end(), 0); std::random_shuffle(indices.begin(), indices.end()); types::list out(k); for (size_t i = 0; i < k; i++) out[i] = tmp[indices[i]]; return out; } } PYTHONIC_NS_END #endif