Hey, that actually works now! Great!

I've also been able to find some range checking errors, so now I'm finally getting somewhere!

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)? I just thought that Random() would return it's value and then that return value would be entered into the arithmetic operation like any other number without affecting it any further, but now it seems that it actually affects what kind of result I can get from the arithmetic operation. Is that understood correctly?

Also, I'm now getting an overflow error in a part of my code used for encrypting and decrypting:

[pascal]CONST C1 = 52845;
C2 = 11719;


FUNCTION Decrypt(Const S: String; Key: Word): String;
VAR
I: Byte;
TempString : String;
BEGIN
TempString := '';
FOR I := 1 TO Length(S) DO BEGIN
TempString := TempString + Char(Byte(S[I]) XOR (Key SHR );
Key := (Byte(S[I]) + Key) * C1 + C2; {<-- getting the overflow error on this line}
END;
Decrypt := TempString;
END;
[/pascal]

I found this function on the internet (I actually believed it was downloaded from Borland!) and haven't changed it. I've tried getting the function to output the value of "(Byte(S[I]) + Key) * C1 + C2" to the screen and the result was always with the range Word.

EDIT:
I found some references to this function:
http://www.bsdg.org/SWAG/ENCRYPT/0036.PAS.html
http://www.q3.nu/trucomania/truco.cgi?100&ing