Quote Originally Posted by PP2005
Hey, that actually works now! Great!
I'm just not completely sure I understand what the problem was... Is it that if you create a arithmetic operation such as the "20 - Random(40)", then the result of that operation must be the same as the result of the function used in the operation (i.e. the Random() function)?
If you use a binary operator on an integer type, the compiler decides the common type between the left and right type, that is the smallest type that can handle both the left and right operand. I.e. the common type of "0..99" and "byte" is 0..255. The common type of "integer" and "word" is -32768..65535.

Before doing the operation, the compiler converts both operands to the common type. Then the compiler does the operation.

Assume random(40) returns 35. On the left side there is a constant, and on the right side there is a word. The smallest type that can handle both 20 and a word is 0..65535. So, 20 is "converted" to 0..65535, and 35 is "converted" to 0..65535. Then the compiler subtracts: 20-35=-15. -15 is not in the range of the common type 0..65535, therefore, you have an arithmetic overflow.