_types.pas:
You don't need C-like weirdnesses with random(). We have a much more sophisticated function in our language
Code:
// not 100% sure of this one. That -0.5 could make it rounded differently.
function RAND(X: Integer): Single;
begin
//Result := (Random(RAND_MAX) / RAND_MAX - 0.5) * X;
Result:=Random()*X;
end;
function RANDI(X: Integer): Integer;
begin
//Result := Round((Abs(Random(RAND_MAX) / RAND_MAX * X)));
Result := Random(X);
end;
I see you made int into integer. May depend on compiler, but generally i guess its safe to assume int = 2 bytes, meaning smallint or word.
http://en.wikipedia.org/wiki/C_data_types
However "int size" in that code can get values from 16 to 128, and other function does size*size*2, which would be 32768. That would overflow, because 32767 is largest allowed for signed. So i'd prolly go with using longint aswell on the size. I don't know how well that asm code manages with that then.
Also, compiling pascal program for 64-bit system would consider integer = int64, would it not? I don't have 64-bit system, and only guessing. Longint type is guaranteed 4 bytes.
Bookmarks