Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen Vermeulen <jtv@precisiontranslationtools.com>2015-04-22 16:43:29 +0300
committerJeroen Vermeulen <jtv@precisiontranslationtools.com>2015-04-22 16:43:29 +0300
commit75bfb758822cc926a1852c6a86a7ce5d153a1320 (patch)
tree7a967ee360aeb4898450888b31fc2ad602d9c7e6 /mert/Data.cpp
parent1083999d3e4447ac347b8bcbb04a0733ae8c3654 (diff)
Thread-safe, platform-agnostic randomizer.
Some places in mert use srandom()/random(), but these are POSIX-specific. The standard alternative, srand()/rand(), is not thread-safe. This module wraps srand()/rand() in mutexes (very short-lived, so should not cost much) so that it relies on just Boost and the C standard library, not on a Unix-like environment. This may reduce the width of the random numbers on some platforms: it goes from "long int" to just "int". If that is a problem, we may have to use Boost's randomizer utilities, or eventually, the C++ ones.
Diffstat (limited to 'mert/Data.cpp')
-rw-r--r--mert/Data.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/mert/Data.cpp b/mert/Data.cpp
index 49c1239e5..428886b99 100644
--- a/mert/Data.cpp
+++ b/mert/Data.cpp
@@ -17,6 +17,7 @@
#include "util/exception.hh"
#include "util/file_piece.hh"
+#include "util/random.hh"
#include "util/tokenize_piece.hh"
#include "util/string_piece.hh"
#include "FeatureDataIterator.h"
@@ -286,7 +287,7 @@ void Data::createShards(size_t shard_count, float shard_size, const string& scor
} else {
//create shards by randomly sampling
for (size_t i = 0; i < floor(shard_size+0.5); ++i) {
- shard_contents.push_back(rand() % data_size);
+ shard_contents.push_back(util::rand_int() % data_size);
}
}