From b26f3590e6451a39af7b598d0531bd50a20312f0 Mon Sep 17 00:00:00 2001
From: Roman Tolchenov <roman.tolchenov@stfc.ac.uk>
Date: Mon, 9 Jul 2018 15:52:04 +0100
Subject: [PATCH] Use single random number generator. Re #22317.

---
 .../CurveFitting/src/FuncMinimizers/FABADAMinimizer.cpp     | 6 ++----
 .../CurveFitting/test/FuncMinimizers/FABADAMinimizerTest.h  | 4 ++--
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/Framework/CurveFitting/src/FuncMinimizers/FABADAMinimizer.cpp b/Framework/CurveFitting/src/FuncMinimizers/FABADAMinimizer.cpp
index 60a8ad16179..97c026344ce 100644
--- a/Framework/CurveFitting/src/FuncMinimizers/FABADAMinimizer.cpp
+++ b/Framework/CurveFitting/src/FuncMinimizers/FABADAMinimizer.cpp
@@ -39,6 +39,8 @@ const size_t LOWER_CONVERGENCE_LIMIT = 350;
 const size_t JUMP_CHECKING_RATE = 200;
 // low jump limit
 const double LOW_JUMP_LIMIT = 1e-25;
+// random number generator
+std::mt19937 rng;
 }
 
 DECLARE_FUNCMINIMIZER(FABADAMinimizer, FABADA)
@@ -352,8 +354,6 @@ void FABADAMinimizer::finalize() {
 * @return :: the step
 */
 double FABADAMinimizer::gaussianStep(const double &jump) {
-  std::mt19937 rng(123 * (int(m_counter) + 45 * int(jump)) +
-                   14 * int(time_t()));
   return Kernel::normal_distribution<double>(0.0, std::abs(jump))(rng);
 }
 
@@ -477,8 +477,6 @@ void FABADAMinimizer::algorithmDisplacement(const size_t &parameterIndex,
     double prob = exp((m_chi2 - chi2New) / (2.0 * m_temperature));
 
     // Decide if changing or not
-    std::mt19937 rng(int(time_t()) +
-                     48 * (int(m_counter) + 76 * int(parameterIndex)));
     double p = std::uniform_real_distribution<double>(0.0, 1.0)(rng);
     if (p <= prob) {
       for (size_t j = 0; j < m_nParams; j++) {
diff --git a/Framework/CurveFitting/test/FuncMinimizers/FABADAMinimizerTest.h b/Framework/CurveFitting/test/FuncMinimizers/FABADAMinimizerTest.h
index 26ddce2a4e2..f1f5ad62963 100644
--- a/Framework/CurveFitting/test/FuncMinimizers/FABADAMinimizerTest.h
+++ b/Framework/CurveFitting/test/FuncMinimizers/FABADAMinimizerTest.h
@@ -178,7 +178,7 @@ public:
     TS_ASSERT_THROWS_NOTHING(fit.execute());
     TS_ASSERT(fit.isExecuted());
 
-    TS_ASSERT_DELTA(fun->getParameter("Height"), 10.0, 0.02);
+    TS_ASSERT_DELTA(fun->getParameter("Height"), 10.0, 0.1);
     TS_ASSERT_DELTA(fun->getParameter("Lifetime"), 0.5, 0.01);
     TS_ASSERT_DELTA(fun->getError(0), 0.7, 1e-1);
     TS_ASSERT_DELTA(fun->getError(1), 0.06, 1e-2);
@@ -194,7 +194,7 @@ public:
     TS_ASSERT_EQUALS(PDF->x(0).size(), 21);
     TS_ASSERT_EQUALS(PDF->y(0).size(), 20);
     TS_ASSERT_DELTA(PDF->y(0)[7], 0.41, 0.3);
-    TS_ASSERT_DELTA(PDF->y(1)[8], 5.24, 1.0);
+    TS_ASSERT_DELTA(PDF->y(1)[8], 3.5, 1.0);
     TS_ASSERT_DELTA(PDF->y(2)[0], 0.44, 0.3);
 
     //  Test CostFunction table
-- 
GitLab