In reviewing your code there are a few things I would point out.
When you provide a seed for randomization you are telling the random number generator to generate the same series of numbers every time it is executed. I would recommend removing this line entirely as it will, by default, rely on the system time as the seed which will ensure a new number is generated each time.
The random() function returns a default value between 0 and 65535. Based on the code that appears below this that checks for the value of a it appears that you intended for the value to fall between 0 and 100.
To accomplish this you can do one of two things to your code:
You can use keep using random() but use the
mod() function to trim your values into the appropriate range.
-OR-
You can use
random(from,to) where you actually define the range/bounds of values that you want to be returned. Since this is built-in, this is the way I would recommend that you do it.
//IF-A
if a <= 20
goodguyxpos = 100
endif
//IF-B
if a >= 21 or a <= 70
goodguyxpos = 400
endif
//IF-C
if a >= 71 or a <= 100
goodguyxpos = 800
endif
These lines actually contain a logic error. I've labeled each of the if statements in order to add some clarity to this explanation.
Suppose that the value of a is 17.
IF-A asks is the value <= 20 (TRUE)
IF-B asks is the value >= 21 (FALSE) -OR- is the value <= 70 (TRUE)
IF-C asks is the value >= 71 (FALSE) -OR- is the value <= 100 (TRUE)
Because part of the -OR- expression is true the entire expression evaluates to true. I would suggest reviewing the
boolean operators documentation to get a better handle on this.
In this case, you should be using -AND- instead because you are wanting to define a range where both bounds must be true.