RNG values need to be always positive.
Solution: Transposing positively by divisor. In all the two places it may happen.
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);
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 ||