Skip to content

Commit c0fca7a

Browse files
committed
Make RNGs thread-local
1 parent 4b26b97 commit c0fca7a

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

IsoSpec++/isoMath.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,8 @@ double InverseLowerIncompleteGamma2(int a, double x)
146146
return s;
147147
}
148148

149-
std::random_device random_dev;
150-
std::mt19937 random_gen(random_dev());
151-
std::uniform_real_distribution<double> stdunif(0.0, 1.0);
149+
thread_local std::mt19937 random_gen(std::random_device{}());
150+
thread_local std::uniform_real_distribution<double> stdunif(0.0, 1.0);
152151

153152
size_t rdvariate_binom(size_t tries, double succ_prob, std::mt19937& rgen)
154153
{

IsoSpec++/isoMath.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ inline double InverseChiSquareCDF2(int k, double x)
7070
return InverseLowerIncompleteGamma2(k, x*tgamma(static_cast<double>(k)/2.0)) * 2.0;
7171
}
7272

73-
extern std::mt19937 random_gen;
74-
extern std::uniform_real_distribution<double> stdunif;
73+
extern thread_local std::mt19937 random_gen;
74+
extern thread_local std::uniform_real_distribution<double> stdunif;
7575

7676
inline double rdvariate_beta_1_b(double b, std::mt19937& rgen = random_gen)
7777
{

0 commit comments

Comments
 (0)