C library function "rand"

Im trying to make some modifications to this game. I dont fully understand some of its code, basically what this is suppose to do is generate a random shooting skill for each new soldier recruited (I think) between 28 - 49 heres the code:

newUnit.shootingACT = 28 + rand(21)/2 + rand(21)/2;

newUnit.shootingMAX = newUnit.shootingACT + 52;

Please correct me if im wrong here but what i think the first part of this is suppose to do is generate a random skill from 28 to 49, but what i cant figure out is the last part /2 + rand(21)/2 ?

Last edited on
+ rand(21)/2 + rand(21)/2 adds two random numbers in the range 0-10
+ rand(21)/2 + rand(21)/2 adds two random numbers in the range 0-10

So if i understand this correctly, the highest possible number i could get using this 28 + rand(21)/2 + rand(21)/2; would be 91 ...correct ?
28+10+10 = 48
Is the chance it would be 10 determined ?

Say if i were to just brake it down to + rand(21)/2 it would be a 50% it could be 10 ?
Each number has the same probability of being the result of that, depending on how accurate is the RNG algorithm used.
so 10 should have a (100/11) % - about 9% -
Topic archived. No new replies allowed.