11 #ifndef EMP_RANDOM_UTILS_H 12 #define EMP_RANDOM_UTILS_H 14 #include "../base/vector.h" 27 for (
size_t i = 0; i < max_count; i++) {
29 if (pos == i)
continue;
30 std::swap(v[i], v[pos]);
43 for (
size_t i = 1; i < size; i++) {
44 size_t val_pos = random.
GetUInt(i+1);
45 seq[i] = seq[val_pos];
53 inline void Choose(
Random & random,
size_t N,
size_t K, std::vector<size_t> & choices) {
58 if (N==K || random.
P(((
double) K)/((
double) N))) { choices[--K] = --N; }
63 inline std::vector<size_t>
Choose(
Random & random,
size_t N,
size_t K) {
64 std::vector<size_t> choices;
65 Choose(random,N,K,choices);
75 for (
size_t i = 0; i < size; i++) bits[i] = random.
P(p);
82 for (
double & v : vals) v = random.
GetDouble(min, max);
89 for (
size_t & v : vals) v = random.
GetUInt(min, max);
97 for (T & v : vals) v = (T) random.
GetDouble((
double) min, (
double) max);
105 for (
size_t i = 0; i < bits.
size(); i++) bits[i] = random.
P(p);
109 template <
typename T>
111 for (T & v : vals) v = (T) random.
GetDouble((
double) min, (
double) max);
size_t size() const
Function to allow drop-in replacement with std::vector<bool>.
Definition: BitVector.h:765
BitVector RandomBitVector(Random &random, size_t size, double p=0.5)
Generate a random BitVector of the specified size.
Definition: random_utils.h:71
void Shuffle(Random &random, emp::vector< T > &v, size_t max_count)
Definition: random_utils.h:25
A versatile and non-patterned pseudo-random-number generator (Mersenne Twister).
Definition: ce_random.h:52
A drop-in replacement for std::vector<bool>, but with extra bitwise logic features.
Definition: BitVector.h:39
A drop-in replacement for std::vector<bool>, with additional bitwise logic features.
size_t size() const
Definition: vector.h:151
constexpr uint32_t GetUInt(const uint32_t max)
Definition: ce_random.h:191
void RandomizeVector(emp::vector< T > &vals, Random &random, T min, T max)
Generate a random vector in the specified type and range.
Definition: random_utils.h:110
constexpr double GetDouble()
Definition: ce_random.h:166
emp::vector< T > RandomVector(Random &random, size_t size, T min, T max)
Generate a random vector in the specified type and range.
Definition: random_utils.h:95
A versatile and non-patterned pseudo-random-number generator.
If we are in emscripten, make sure to include the header.
Definition: array.h:37
emp::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.
Definition: random_utils.h:87
emp::vector< double > RandomDoubleVector(Random &random, size_t size, double min, double max)
Generate a random double vector in the specified range.
Definition: random_utils.h:80
#define emp_assert(...)
Definition: assert.h:199
emp::vector< size_t > GetPermutation(Random &random, size_t size)
Return an emp::vector<int> numbered 0 through size-1 in a random order.
Definition: random_utils.h:40
constexpr bool P(const double _p)
Definition: ce_random.h:216
void RandomizeBitVector(BitVector &bits, Random &random, double p=0.5)
Generate a random BitVector of the specified size.
Definition: random_utils.h:102
void Choose(Random &random, size_t N, size_t K, std::vector< size_t > &choices)
Choose K positions from N possibilities.
Definition: random_utils.h:53