random_utils.hpp
Helper functions for Random for common random tasks. Status: RELEASE.
This file is part of Empirical, https://github.com/devosoft/Empirical Copyright (C) 2016-2025 Michigan State University MIT Software license; see doc/LICENSE.md
Defines
-
INCLUDE_EMP_MATH_RANDOM_UTILS_HPP_GUARD
Functions
-
template<typename T, typename RAND_T>
inline auto SelectRandom(RAND_T &random, const T &container) Choose a random element from an indexable container.
-
template<typename T, typename RAND_T>
inline void Shuffle(RAND_T &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, typename RAND_T>
inline void ShuffleRange(RAND_T &random, vector<T> &v, size_t first, size_t last)
-
inline vector<size_t> GetPermutation(auto &random, size_t size)
Return an vector<int> numbered 0 through size-1 in a random order.
-
inline void Choose(auto &random, size_t N, size_t K, std::vector<size_t> &choices)
Choose K positions from N possibilities.
-
inline BitVector RandomBitVector(auto &random, size_t size, double p = 0.5)
Generate a random BitVector of the specified size.
-
inline vector<double> RandomDoubleVector(auto &random, size_t size, double min, double max)
Generate a random double vector in the specified range.
-
inline vector<size_t> RandomUIntVector(auto &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(auto &random, size_t size, T min, T max) Generate a random vector in the specified type and range.
-
inline void RandomizeBitVector(BitVector &bits, auto &random, double p = 0.5)
Generate a random BitVector of the specified size.
-
template<typename T, typename RAND_T>
inline void RandomizeVector(vector<T> &vals, RAND_T &random, T min, T max) Generate a random vector in the specified type and range.
-
class RandProbability
- #include <random_utils.hpp>
Public Functions
-
inline RandProbability(double p)
Private Members
-
const double p
-
inline RandProbability(double p)
-
class LowProbability
- #include <random_utils.hpp>
Public Functions
-
inline LowProbability(double p)
Private Functions
-
inline double CalcScale(double p) const
-
inline LowProbability(double p)