diff --git a/src/ccutil/helpers.h b/src/ccutil/helpers.h index 20a48201..6bfcf207 100644 --- a/src/ccutil/helpers.h +++ b/src/ccutil/helpers.h @@ -27,7 +27,6 @@ #include #include // for std::find #include -#include #include #include @@ -73,9 +72,10 @@ inline const std::vector split(const std::string &s, char c) { // http://en.wikipedia.org/wiki/Linear_congruential_generator. class TRand { public: + TRand() = default; // Sets the seed to the given value. void set_seed(uint64_t seed) { - e.seed(seed); + seed_ = seed; } // Sets the seed using a hash of a string. void set_seed(const std::string &str) { @@ -85,7 +85,8 @@ public: // Returns an integer in the range 0 to INT32_MAX. int32_t IntRand() { - return e(); + Iterate(); + return seed_ >> 33; } // Returns a floating point value in the range [-range, range]. double SignedRand(double range) { @@ -97,10 +98,14 @@ public: } private: - std::linear_congruential_engine e; + // Steps the generator to the next value. + void Iterate() { + seed_ *= 6364136223846793005ULL; + seed_ += 1442695040888963407ULL; + } + + // The current value of the seed. + uint64_t seed_{1}; }; // Remove newline (if any) at the end of the string. diff --git a/unittest/intsimdmatrix_test.cc b/unittest/intsimdmatrix_test.cc index 95688eed..ca473adb 100644 --- a/unittest/intsimdmatrix_test.cc +++ b/unittest/intsimdmatrix_test.cc @@ -92,9 +92,9 @@ protected: } // Compare sum of all results with expected value. #ifdef FAST_FLOAT - EXPECT_FLOAT_EQ(total, 337852.16f); + EXPECT_FLOAT_EQ(total, -423236.53f); #else - EXPECT_FLOAT_EQ(total, 337849.39354684710); + EXPECT_FLOAT_EQ(total, -423243.392011); #endif }