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-23 15:27:21 +0300
committerJeroen Vermeulen <jtv@precisiontranslationtools.com>2015-04-23 19:46:04 +0300
commit38d790cac0f21de9ff8951dce0bb5d522ad46c0d (patch)
treea65df558350c77e148e3c2fc6e40efa1ed6367e4 /moses/Parameter.cpp
parent4b47e1148c7cfe771c8e813cb9d741c2de44ed42 (diff)
Add cross-platform randomizer module.
The code uses two mechanisms for generating random numbers: srand()/rand(), which is not thread-safe, and srandom()/random(), which is POSIX-specific. Here I add a util/random.cc module that centralizes these calls, and unifies some common usage patterns. If the implementation is not good enough, we can now change it in a single place. To keep things simple, this uses the portable srand()/rand() but protects them with a lock to avoid concurrency problems. The hard part was to keep the regression tests passing: they rely on fixed sequences of random numbers, so a small code change could break them very thoroughly. Util::rand(), for wide types like size_t, calls std::rand() not once but twice. This behaviour was generalized into utils::wide_rand() and friends.
Diffstat (limited to 'moses/Parameter.cpp')
-rw-r--r--moses/Parameter.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/moses/Parameter.cpp b/moses/Parameter.cpp
index e43c69d22..b6773fa13 100644
--- a/moses/Parameter.cpp
+++ b/moses/Parameter.cpp
@@ -31,6 +31,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "InputFileStream.h"
#include "StaticData.h"
#include "util/exception.hh"
+#include "util/random.hh"
#include <boost/program_options.hpp>
@@ -1392,7 +1393,7 @@ struct Credit {
this->contact = contact ;
this->currentPursuits = currentPursuits ;
this->areaResponsibility = areaResponsibility;
- this->sortId = rand() % 1000;
+ this->sortId = util::rand_excl(1000);
}
bool operator<(const Credit &other) const {