mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2024-11-27 12:49:35 +08:00
Restore original congruential random number generator
Some checks are pending
CodeQL / Analyze (cpp) (push) Waiting to run
Some checks are pending
CodeQL / Analyze (cpp) (push) Waiting to run
This reverts commit32fee19447
("Fix linear congruential random number generator"), commit2252936fc8
("Use linear congruential random number generator from C++11.") and commit7b8af67eb5
("[test] Fix intsimdmatrix test. Update result value based on updated TRand engine."). It restores the original congruential random number generator and the related unittest. Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
parent
66cf74f2dd
commit
5af6cacf84
@ -27,7 +27,6 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <algorithm> // for std::find
|
#include <algorithm> // for std::find
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <random>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -73,9 +72,10 @@ inline const std::vector<std::string> split(const std::string &s, char c) {
|
|||||||
// http://en.wikipedia.org/wiki/Linear_congruential_generator.
|
// http://en.wikipedia.org/wiki/Linear_congruential_generator.
|
||||||
class TRand {
|
class TRand {
|
||||||
public:
|
public:
|
||||||
|
TRand() = default;
|
||||||
// Sets the seed to the given value.
|
// Sets the seed to the given value.
|
||||||
void set_seed(uint64_t seed) {
|
void set_seed(uint64_t seed) {
|
||||||
e.seed(seed);
|
seed_ = seed;
|
||||||
}
|
}
|
||||||
// Sets the seed using a hash of a string.
|
// Sets the seed using a hash of a string.
|
||||||
void set_seed(const std::string &str) {
|
void set_seed(const std::string &str) {
|
||||||
@ -85,7 +85,8 @@ public:
|
|||||||
|
|
||||||
// Returns an integer in the range 0 to INT32_MAX.
|
// Returns an integer in the range 0 to INT32_MAX.
|
||||||
int32_t IntRand() {
|
int32_t IntRand() {
|
||||||
return e();
|
Iterate();
|
||||||
|
return seed_ >> 33;
|
||||||
}
|
}
|
||||||
// Returns a floating point value in the range [-range, range].
|
// Returns a floating point value in the range [-range, range].
|
||||||
double SignedRand(double range) {
|
double SignedRand(double range) {
|
||||||
@ -97,10 +98,14 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::linear_congruential_engine<std::uint_fast32_t,
|
// Steps the generator to the next value.
|
||||||
6364136223846793005ULL,
|
void Iterate() {
|
||||||
1442695040888963407ULL,
|
seed_ *= 6364136223846793005ULL;
|
||||||
UINT64_MAX> e;
|
seed_ += 1442695040888963407ULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The current value of the seed.
|
||||||
|
uint64_t seed_{1};
|
||||||
};
|
};
|
||||||
|
|
||||||
// Remove newline (if any) at the end of the string.
|
// Remove newline (if any) at the end of the string.
|
||||||
|
@ -92,9 +92,9 @@ protected:
|
|||||||
}
|
}
|
||||||
// Compare sum of all results with expected value.
|
// Compare sum of all results with expected value.
|
||||||
#ifdef FAST_FLOAT
|
#ifdef FAST_FLOAT
|
||||||
EXPECT_FLOAT_EQ(total, 337852.16f);
|
EXPECT_FLOAT_EQ(total, -423236.53f);
|
||||||
#else
|
#else
|
||||||
EXPECT_FLOAT_EQ(total, 337849.39354684710);
|
EXPECT_FLOAT_EQ(total, -423243.392011);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user