Revision f857128b src/sim/cnumgen.cc

View differences:

src/sim/cnumgen.cc
34 34
#define M_E     2.7182818284590452353602874713527
35 35
#endif
36 36

  
37
cNumberGenerator::cNumberGenerator(unsigned nrRngs, unsigned long * seeds) :
38
	nrRngs(nrRngs) {
37
cNumberGenerator::cNumberGenerator() : nrRNGs(0) {
39 38
	if (simulation.isRunning()) {
40 39
		throw cRuntimeError(
41 40
				"Cannot (yet) create new instance of cNumberGenerator"
42 41
					" at runtime due to potentially concurrent access to"
43 42
					" the central seed generator.");
44 43
	}
45

  
46
	rngs = (cRNG**) new cMersenneTwister*[nrRngs];
47
	for (unsigned i = 0; i < nrRngs; i++) {
48
		rngs[i] = new cMersenneTwister();
49
		rngs[i]->seed(seeds[i]);
50
	}
51 44
}
52 45

  
53 46

  
54 47
cNumberGenerator::~cNumberGenerator() {
55
	for (int i = 0; i < nrRngs; i++)
48
	for (int i = 0; i < nrRNGs; i++)
56 49
		delete rngs[i];
57 50

  
58 51
}
59 52

  
60 53
void cNumberGenerator::checkBounds(int rngId) {
61
	if (nrRngs < rngId)
54
	if (nrRNGs <= rngId)
62 55
		throw cRuntimeError(
63
				"cNumberGenerator only has %d < %d local generators.", nrRngs,
56
				"cNumberGenerator only has %d < %d local generators.", nrRNGs,
64 57
				rngId);
65 58
}
59

  
60
void cNumberGenerator::setupSeeds(unsigned nrRng, unsigned long * seeds) {
61
    nrRNGs = nrRng;
62
    rngs = (cRNG**) new cMersenneTwister*[nrRNGs];
63
    for (int i = 0; i < nrRNGs; i++) {
64
        rngs[i] = new cMersenneTwister();
65
        rngs[i]->seed(seeds[i]);
66
    }
67
}
66 68
//----------------------------------------------------------------------------
67 69
//
68 70
//  C O N T I N U O U S

Also available in: Unified diff