Aslona wizard PRNG question

Feb 7, 9:57 pm
#1
Joined: Sep 5, 2010
Interests: make more ivans!
Posts: 310
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.
Feb 10, 2:55 am
#2
Joined: Apr 2, 2014
Occupation: Navastating
Location: Aslona
Posts: 836
Yeah, that's a bug. It should be as you write, RAND() % 4 or RAND_4.
Feb 10, 1:15 pm
#3
Joined: Sep 5, 2010
Interests: make more ivans!
Posts: 310
thank you for confirming. i found it in in my crusade against `RAND() % n`, and decided to ask.
Feb 11, 2:30 am
#4
Joined: Sep 8, 2010
Occupation: Petty Functionary
Location: Drinking pea soup in the world map
Interests: Mangoes
Posts: 1,225
Ooh nice spotting, thanks V!
Batman? wrote
its been so long since i had gotten that far i didnt think it through. arrrr!!!!!!
Jump to