Skip to content

Commit c1bb752

Browse files
committed
Simplify and clean code related to class TRand
Signed-off-by: Stefan Weil <[email protected]>
1 parent 9f17a3f commit c1bb752

File tree

3 files changed

+3
-9
lines changed

3 files changed

+3
-9
lines changed

src/ccstruct/imagedata.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,8 @@ void DocumentData::Shuffle() {
526526
TRand random;
527527
// Different documents get shuffled differently, but the same for the same
528528
// name.
529-
random.set_seed(document_name_.c_str());
529+
std::hash<std::string> hasher;
530+
random.set_seed(static_cast<uint64_t>(hasher(document_name_)));
530531
int num_pages = pages_.size();
531532
// Execute one random swap for each page in the document.
532533
for (int i = 0; i < num_pages; ++i) {

src/ccutil/helpers.h

-7
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
#include <climits> // for INT_MIN, INT_MAX
2525
#include <cmath> // std::isfinite
2626
#include <cstdio>
27-
#include <cstring>
2827
#include <algorithm> // for std::find
29-
#include <functional>
3028
#include <string>
3129
#include <vector>
3230

@@ -77,11 +75,6 @@ class TRand {
7775
void set_seed(uint64_t seed) {
7876
seed_ = seed;
7977
}
80-
// Sets the seed using a hash of a string.
81-
void set_seed(const std::string &str) {
82-
std::hash<std::string> hasher;
83-
set_seed(static_cast<uint64_t>(hasher(str)));
84-
}
8578

8679
// Returns an integer in the range 0 to INT32_MAX.
8780
int32_t IntRand() {

src/lstm/lstmrecognizer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ class TESS_API LSTMRecognizer {
286286
protected:
287287
// Sets the random seed from the sample_iteration_;
288288
void SetRandomSeed() {
289-
int64_t seed = static_cast<int64_t>(sample_iteration_) * 0x10000001;
289+
int64_t seed = sample_iteration_ * 0x10000001LL;
290290
randomizer_.set_seed(seed);
291291
randomizer_.IntRand();
292292
}

0 commit comments

Comments
 (0)