inp.c, randnumb.c, option seedinfo

Print seed information only when option is set.
This commit is contained in:
h_vogt 2016-08-07 09:24:58 +02:00 committed by rlar
parent d49ece80e3
commit 6704c04a42
3 changed files with 15 additions and 2 deletions

View File

@ -350,6 +350,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=*/
@ -357,7 +360,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 */

View File

@ -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);

View File

@ -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;
}