@@ -136,30 +136,37 @@ std::vector<T> gather(const std::vector<T>& input, const std::vector<uint32_t>&
136136
137137
138138// === Random number generation
139- extern std::random_device util_random_device;
140- extern std::mt19937 util_mersenne_twister;
139+ extern std::mt19937 util_mersenne_twister; // deterministically seeded on startup
141140
141+ // Generates a random double in the range [0, 1].
142+ // It is seeded deterministically on startup, so every run of the program will produce the same sequence.
142143inline double randomUnit () {
143144 std::uniform_real_distribution<double > dist (0 ., 1 .);
144145 return dist (util_mersenne_twister);
145146}
146147
148+ // Generates a random double in the range [minVal, maxVal].
149+ // It is seeded deterministically on startup, so every run of the program will produce the same sequence.
147150inline double randomReal (double minVal, double maxVal) {
148151 std::uniform_real_distribution<double > dist (minVal, maxVal);
149152 return dist (util_mersenne_twister);
150153}
151154
152155// Generate a random int in the INCLUSIVE range [lower,upper]
156+ // It is seeded deterministically on startup, so every run of the program will produce the same sequence.
153157inline int randomInt (int lower, int upper) {
154158 std::uniform_int_distribution<int > dist (lower, upper);
155159 return dist (util_mersenne_twister);
156160}
157161// Generate a random size_t in the range [0, N)
162+ // It is seeded deterministically on startup, so every run of the program will produce the same sequence.
158163inline size_t randomIndex (size_t size) {
159164 std::uniform_int_distribution<size_t > dist (0 , size - 1 );
160165 return dist (util_mersenne_twister);
161166}
162167
168+ // Generates a random number from a normal (Gaussian) distribution with given mean and standard deviation.
169+ // It is seeded deterministically on startup, so every run of the program will produce the same sequence.
163170inline double randomNormal (double mean = 0.0 , double stddev = 1.0 ) {
164171 std::normal_distribution<double > dist{mean, stddev};
165172 return dist (util_mersenne_twister);
0 commit comments