random_utils.hpp

Helper functions for Random for common random tasks. Status: RELEASE.

Functions

template<typename T>
inline auto SelectRandom(Random &random, const T &container)

Choose a random element from an indexable container.

template<typename T>
inline void Shuffle(Random &random, vector<T> &v, size_t max_count)

Randomly reorder all of the elements in a vector. If max_count is provided, just make sure that the first max_count entries are randomly drawn from entire vector.

template<typename T>
inline void Shuffle(Random &random, vector<T> &v)
template<typename T>
inline void ShuffleRange(Random &random, vector<T> &v, size_t first, size_t last)
inline vector<size_t> GetPermutation(Random &random, size_t size)

Return an vector<int> numbered 0 through size-1 in a random order.

inline void Choose(Random &random, size_t N, size_t K, std::vector<size_t> &choices)

Choose K positions from N possibilities.

inline std::vector<size_t> Choose(Random &random, size_t N, size_t K)
inline BitVector RandomBitVector(Random &random, size_t size, double p = 0.5)

Generate a random BitVector of the specified size.

inline vector<double> RandomDoubleVector(Random &random, size_t size, double min, double max)

Generate a random double vector in the specified range.

inline vector<size_t> RandomUIntVector(Random &random, size_t size, size_t min, size_t max)

Generate a random size_t vector in the specified range.

template<typename T>
inline vector<T> RandomVector(Random &random, size_t size, T min, T max)

Generate a random vector in the specified type and range.

inline void RandomizeBitVector(BitVector &bits, Random &random, double p = 0.5)

Generate a random BitVector of the specified size.

template<typename T>
inline void RandomizeVector(vector<T> &vals, Random &random, T min, T max)

Generate a random vector in the specified type and range.

inline size_t CountRngTouches(std::function<void(Random&)> routine)