20#if defined HAVE_VALGRIND_HEADERS
21#include <valgrind/memcheck.h>
35#define STD_RNG_ALGO std::mt19937
39struct RandomNumberGenerator
43 RandomNumberGenerator()
46 bool bRepeatable = (getenv(
"SAL_RAND_REPEATABLE") !=
nullptr) || (getenv(
"RR") !=
nullptr);
49#if defined HAVE_VALGRIND_HEADERS
50 if (RUNNING_ON_VALGRIND)
61 std::random_device rd;
69 catch (std::runtime_error& e)
71 SAL_WARN(
"comphelper",
"Using std::random_device failed: " << e.what());
77RandomNumberGenerator& GetTheRandomNumberGenerator()
79 static RandomNumberGenerator
RANDOM;
87 std::uniform_int_distribution<int> dist(
a, b);
88 auto& gen = GetTheRandomNumberGenerator();
89 std::scoped_lock<std::mutex> g(gen.mutex);
90 return dist(gen.global_rng);
96 std::uniform_int_distribution<unsigned int> dist(
a, b);
97 auto& gen = GetTheRandomNumberGenerator();
98 std::scoped_lock<std::mutex> g(gen.mutex);
99 return dist(gen.global_rng);
105 std::uniform_int_distribution<size_t> dist(
a, b);
106 auto& gen = GetTheRandomNumberGenerator();
107 std::scoped_lock<std::mutex> g(gen.mutex);
108 return dist(gen.global_rng);
115 std::uniform_real_distribution<double> dist(
a, b);
116 auto& gen = GetTheRandomNumberGenerator();
117 std::scoped_lock<std::mutex> g(gen.mutex);
118 return dist(gen.global_rng);
#define SAL_WARN(area, stream)
size_t uniform_size_distribution(size_t a, size_t b)
uniform distribution in [a,b]
double uniform_real_distribution(double a, double b)
uniform distribution in [a,b)
unsigned int uniform_uint_distribution(unsigned int a, unsigned int b)
uniform distribution in [a,b]
int uniform_int_distribution(int a, int b)
uniform distribution in [a,b]