Seed the randomizer once, not every time.

This bit of mira code used to re-seed the randomizer on every call, instead
of just once on startup.  The result of time(NULL) was used as a seed, meaning
that every such call to the randomizer within the same second would return the
same value.
This commit is contained in:
Jeroen Vermeulen 2015-04-24 20:00:07 +07:00
parent 55a4789a8b
commit 10bd942127
2 changed files with 2 additions and 4 deletions

View File

@ -46,6 +46,7 @@ namespace mpi = boost::mpi;
#include "moses/FF/PhrasePairFeature.h"
#include "moses/FF/WordPenaltyProducer.h"
#include "moses/LM/Base.h"
#include "util/random.hh"
using namespace Mira;
using namespace std;
@ -54,6 +55,7 @@ namespace po = boost::program_options;
int main(int argc, char** argv)
{
util::rand_init();
size_t rank = 0;
size_t size = 1;
#ifdef MPI_ENABLE

View File

@ -38,10 +38,6 @@ template <class T> bool from_string(T& t, const std::string& s, std::ios_base& (
struct RandomIndex {
ptrdiff_t operator()(ptrdiff_t max) {
// TODO: Don't seed the randomizer here. If this function gets called
// multiple times in the same second, it will return the same value on
// each of those calls.
util::rand_init();
return util::rand_excl(max);
}
};