2#include "SimpleRandomizer.h"
6SimpleRandomizer::SimpleRandomizer(uint seed)
9 srand((
unsigned int) time(NULL));
11 srand((
unsigned int) seed);
17 return p + (int)( (
double)(q-p+1) * (rand() / (RAND_MAX + 1.0)));
23 return (
int)( (double)(size) * (rand() / (RAND_MAX + 1.0)));
29 return rand() / (double(RAND_MAX));
33void SimpleRandomizer::registerParameters(StateP s)
35 s->getRegistry()->registerEntry(
"randomizer.seed", (voidP)
new uint(0), ECF::UINT,
36 "randomizer seed, 0 uses time(NULL) (default: 0)");
43 if(state->getRegistry()->isModified(
"randomizer.seed")) {
44 voidP sptr = state->getRegistry()->getEntry(
"randomizer.seed");
45 seed = *((
int*)sptr.get());
48 uint *memSeed =
new uint;
51 srand((
unsigned int) seed);
54 srand((uint) time(NULL) + state->getCommunicator()->getCommRank() + (uint) memSeed);
57 srand((
unsigned int) time(NULL) + (
unsigned int) *memSeed);
bool initialize(StateP s)
double getRandomDouble()
Returns random double.
int getRandomInteger(int p, int q)
Returns random integer in [p, q].