From 4756cb3a5b5fa562f2927095346425346e2663ea Mon Sep 17 00:00:00 2001 From: h_vogt Date: Sun, 7 Aug 2016 09:24:58 +0200 Subject: [PATCH] inp.c, randnumb.c, option seedinfo Print seed information only when option is set. --- src/frontend/inp.c | 5 ++++- src/include/ngspice/randnumb.h | 1 + src/maths/misc/randnumb.c | 11 ++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/frontend/inp.c b/src/frontend/inp.c index 2f53fc644..d12f30b93 100644 --- a/src/frontend/inp.c +++ b/src/frontend/inp.c @@ -316,6 +316,9 @@ eval_seed_opt(struct line *deck) if (*line == '*') continue; if (ciprefix(".option", line) || ciprefix("option", line)) { + /* option seedinfo */ + if (strstr(line, "seedinfo")) + setseedinfo(); char *begtok = strstr(line, "seed="); if (begtok) begtok = &begtok[5]; /*skip seed=*/ @@ -323,7 +326,7 @@ eval_seed_opt(struct line *deck) if (has_seed) fprintf(cp_err, "Warning: Multiple 'option seed=val|random' found!\n"); char *token = gettok(&begtok); - /* option seed=random */ + /* option seed=random [seed='random'] */ if (eq(token, "random") || eq(token, "{random}")) { time_t acttime = time(NULL); /* get random value from time in seconds since 1.1.1970 */ diff --git a/src/include/ngspice/randnumb.h b/src/include/ngspice/randnumb.h index 4fc7b6a6c..881175fcf 100644 --- a/src/include/ngspice/randnumb.h +++ b/src/include/ngspice/randnumb.h @@ -3,6 +3,7 @@ #include "ngspice/wordlist.h" extern void com_sseed(wordlist *wl); +extern void setseedinfo(void); /* initialize random number generators */ extern void initw(void); diff --git a/src/maths/misc/randnumb.c b/src/maths/misc/randnumb.c index d01e041e2..a31b3eb56 100644 --- a/src/maths/misc/randnumb.c +++ b/src/maths/misc/randnumb.c @@ -68,6 +68,7 @@ double CombLCGTaus(void); float CombLCGTaus2(void); void rgauss(double* py1, double* py2); +static bool seedinfo = FALSE; /* Check if a seed has been set by the command 'set rndseed=value' @@ -322,5 +323,13 @@ com_sseed(wordlist *wl) cp_vset("rndseed", CP_NUM, &newseed); } - printf("\nSeed value for random number generator is set to %d\n", newseed); + if (seedinfo) + printf("\nSeed value for random number generator is set to %d\n", newseed); +} + + +void +setseedinfo(void) +{ + seedinfo = TRUE; }