Repeatable seeding is working.
authorEric S. Raymond <esr@thyrsus.com>
Thu, 25 May 2017 22:52:39 +0000 (18:52 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 23 Mar 2023 15:28:53 +0000 (11:28 -0400)
main.c

diff --git a/main.c b/main.c
index 1288540754b1a9ae173f22c754080b8bfdcc3799..5a7c523a25963343c8ba17cd56dd9a1c8084e4ec 100644 (file)
--- a/main.c
+++ b/main.c
@@ -99,7 +99,8 @@ int main(int argc, char *argv[]) {
        lcgstate.a = 1093;
        lcgstate.c = 221587;
        lcgstate.m = 1048576;
-       set_seed((long)time(NULL));
+       long seedval = (long)time(NULL);
+       set_seed(seedval);
 
 /*  Read the database if we have not yet done so */
 
@@ -132,6 +133,9 @@ L1: SETUP= -1;
        LIMIT=330;
        if(NOVICE)LIMIT=1000;
 
+       if (logfp)
+           fprintf(logfp, "seed %ld\n", seedval);
+       
        for (;;) {
            do_command(stdin);
        }
@@ -140,7 +144,12 @@ L1:        SETUP= -1;
 static bool fallback_handler(signed char *buf)
 /* fallback handler for commands not handled by FORTRANish parser */
 {
-    printf("Fallback handler sees: %s\n", buf);
+    long sv;
+    if (sscanf(buf, "seed %ld", &sv) == 1) {
+       set_seed(sv);
+       printf("Seed set to %ld\n", sv);
+       return true;
+    }
     return false;
 }