Aslona wizard PRNG question

https://attnam.com/topics/Aslona-wizard-PRNG-question

The Cathedral of Attnam > IVAN Development

#1 Feb 7, 9:57 pm Hide

vasiliy

in aslonawizard AI, there is this code:
  //k8: i believe that it meant to be `RAND_4`
  if (NearestEnemy && NearestEnemy->GetPos().IsAdjacent(Pos) &&
      (!(RAND() & 4) || StateIsActivated(PANIC)))
i suspect that what really should be here is `RAND() % 4` (or `RAND_4`, or `RAND_N(4)`), because `RAND() & 4` is the same as `RAND() & 1`, actually — it simply selects another bit, but it is still only two possible values.
#2 Feb 10, 2:55 am Hide

red_kangaroo

Yeah, that's a bug. It should be as you write, RAND() % 4 or RAND_4.
#3 Feb 10, 1:15 pm Hide

vasiliy

thank you for confirming. i found it in in my crusade against `RAND() % n`, and decided to ask.
#4 Feb 11, 2:30 am Hide

fejoa

Ooh nice spotting, thanks V!