If divident negative, then remainder is negative too.
authorNHOrus <jy6x2b32pie9@yahoo.com>
Mon, 11 Sep 2017 18:20:46 +0000 (21:20 +0300)
committerNHOrus <jy6x2b32pie9@yahoo.com>
Mon, 11 Sep 2017 18:27:57 +0000 (21:27 +0300)
RNG values need to be always positive.
Solution: Transposing positively by divisor. In all the two places it may happen.

misc.c
saveresume.c

diff --git a/misc.c b/misc.c
index 302e61cc641d4faeac7b176839ddd2aa05cac9a1..80e4352b74b7b2ea8feee8a2d91798e50d61c9f7 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -646,8 +646,10 @@ bool tstbit(long mask, int bit)
 void set_seed(int32_t seedval)
 /* Set the LCG seed */
 {
-    game.lcg_x = (uint32_t) seedval % LCG_M;
-
+    game.lcg_x = seedval % LCG_M;
+    if (game.lcg_x < 0) {
+        game.lcg_x = LCG_M + game.lcg_x;
+    }
     // once seed is set, we need to generate the Z`ZZZ word
     for (int i = 0; i < 5; ++i) {
         game.zzword[i] = 'A' + randrange(26);
index f1d52d458423cedd5e01e7bff1dcfc4c45288eff..8bd4418f9e51ac8e2ca0f2ef41b4b4b7cf4e5f00 100644 (file)
@@ -145,6 +145,11 @@ bool is_valid(struct game_t* valgame)
         valgame->lcg_x %= LCG_M;
     }
 
+    /* Check for RNG underflow. Transpose */
+    if (valgame->lcg_x < LCG_M) {
+        valgame->lcg_x = LCG_M + (valgame->lcg_x % LCG_M);
+    }
+
     /*  Bounds check for locations */
     if ( valgame->chloc  < -1 || valgame->chloc  > NLOCATIONS ||
          valgame->chloc2 < -1 || valgame->chloc2 > NLOCATIONS ||