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/evaluator.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/evaluator.cpp')
-rw-r--r--mert/evaluator.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/mert/evaluator.cpp b/mert/evaluator.cpp
index 026abf397..61775a354 100644
--- a/mert/evaluator.cpp
+++ b/mert/evaluator.cpp
@@ -16,6 +16,7 @@
#include "Timer.h"
#include "Util.h"
#include "Data.h"
+#include "util/random.hh"
using namespace std;
using namespace MosesTuning;
@@ -94,7 +95,7 @@ void EvaluatorUtil::evaluate(const string& candFile, int bootstrap, bool nbest_i
for (int i = 0; i < bootstrap; ++i) {
ScoreData scoredata(g_scorer);
for (int j = 0; j < n; ++j) {
- int randomIndex = random() % n;
+ int randomIndex = util::rand_int() % n;
scoredata.add(entries[randomIndex], j);
}
g_scorer->setScoreData(&scoredata);
@@ -284,10 +285,10 @@ void InitSeed(const ProgramOption *opt)
{
if (opt->has_seed) {
cerr << "Seeding random numbers with " << opt->seed << endl;
- srandom(opt->seed);
+ util::rand_int_init(opt->seed);
} else {
cerr << "Seeding random numbers with system clock " << endl;
- srandom(time(NULL));
+ util::rand_int_init();
}
}