diff --git a/src/main.c b/src/main.c index 089b31d2c..ca5501983 100644 --- a/src/main.c +++ b/src/main.c @@ -887,9 +887,10 @@ main(int argc, char **argv) cp_program = ft_sim->simulator; - int ii = getpid(); + /* initialze random number generator with seed = 1 */ + int ii = 1; cp_vset("rndseed", CP_NUM, &ii); - checkseed(); + com_sseed(NULL); /* --- Process command line options --- */ for (;;) { diff --git a/src/maths/misc/randnumb.c b/src/maths/misc/randnumb.c index ea461f9fe..d01e041e2 100644 --- a/src/maths/misc/randnumb.c +++ b/src/maths/misc/randnumb.c @@ -99,7 +99,6 @@ void checkseed(void) /* uniform random number generator, interval [-1 .. +1[ */ double drand(void) { - checkseed(); // return ( 2.0*((double) (RR_MAX-abs(rand())) / (double)RR_MAX-0.5)); return 2.0 * CombLCGTaus() - 1.0; } @@ -205,7 +204,6 @@ double gauss0(void) static double glgset = 0.0; double fac,r,v1,v2; if (gliset) { - checkseed(); do { v1 = 2.0 * CombLCGTaus() - 1.0; v2 = 2.0 * CombLCGTaus() - 1.0; @@ -228,7 +226,6 @@ double gauss0(void) double gauss1(void) { double fac, r, v1, v2; - checkseed(); do { v1 = 2.0 * CombLCGTaus() - 1.0; v2 = 2.0 * CombLCGTaus() - 1.0; @@ -249,7 +246,6 @@ double gauss1(void) void rgauss(double* py1, double* py2) { double x1, x2, w; - checkseed(); do { x1 = 2.0 * CombLCGTaus() - 1.0; x2 = 2.0 * CombLCGTaus() - 1.0; @@ -270,7 +266,6 @@ int poisson(double lambda) { int k=0; //Counter const int max_k = 1000; //k upper limit - checkseed(); double p = CombLCGTaus(); //uniform random number double P = exp(-lambda); //probability double sum=P; //cumulant @@ -288,7 +283,6 @@ int poisson(double lambda) double exprand(double mean) { double expval; - checkseed(); expval = -log(CombLCGTaus()) * mean; return expval; } @@ -313,14 +307,20 @@ com_sseed(wordlist *wl) srand((unsigned int)newseed); TausSeed(); } - else - if ((sscanf(wl->wl_word, " %d ", &newseed) != 1) || (newseed <= 0) || (newseed > INT_MAX)) { - fprintf(cp_err, "Warning: Cannot use %s as seed!\n\n", wl->wl_word); - return; - } - else { - srand((unsigned int)newseed); - TausSeed(); - } + else if ((sscanf(wl->wl_word, " %d ", &newseed) != 1) || + (newseed <= 0) || (newseed > INT_MAX)) + { + fprintf(cp_err, + "\nWarning: Cannot use %s as seed!\n" + " Command 'setseed %s' ignored.\n\n", + wl->wl_word, wl->wl_word); + return; + } + else { + srand((unsigned int)newseed); + TausSeed(); + cp_vset("rndseed", CP_NUM, &newseed); + } + printf("\nSeed value for random number generator is set to %d\n", newseed); } diff --git a/src/sharedspice.c b/src/sharedspice.c index bd037d4d2..4544f2acc 100644 --- a/src/sharedspice.c +++ b/src/sharedspice.c @@ -582,9 +582,10 @@ ngSpice_Init(SendChar* printfcn, SendStat* statusfcn, ControlledExit* ngspiceexi /* program name*/ cp_program = ft_sim->simulator; - int ii = getpid(); + /* initialze random number generator with seed = 1 */ + int ii = 1; cp_vset("rndseed", CP_NUM, &ii); - checkseed(); + com_sseed(NULL); /* set a boolean variable to be used in .control sections */ bool sm = TRUE; diff --git a/src/spinit.in b/src/spinit.in index 305e7dfea..2ca7e3d1e 100644 --- a/src/spinit.in +++ b/src/spinit.in @@ -2,7 +2,7 @@ alias exit quit alias acct rusage all set x11lineararcs -*set rndseed=12 +*setseed 12 ** ascii rawfile ** *set filetype=ascii ** frontend debug output **