uSystemLibrary: Added Random(ARange: integer): integer; overloaded method

In the original uSystemLibrary only has the Random; method. And for some reason was missing its overloaded version Random(ARange: integer): Integer;

So I updated the uSystemLibrary to include the Random(ARange: integer): integer;.
What I did was the updated the uSystemLibrary.pas with the following:

  1. Edit Line 254 to the following:
DefineMethod( 'Random',              1, tkVariant, nil, RandomProc,						false, 1, 'ARange: integer' );
  1. Then starting at Line 783, I updated the RandomProc to be the following:
procedure TatSystemLibrary.RandomProc(AMachine:TatVirtualMachine);
begin
  with AMachine do
	begin
		case InputArgCount of
			0: ReturnOutputArg( Random );
			1: ReturnOutPutArg( Random( GetInputArgAsInteger(0) ) );
		end;
	end;
end;

If you edit the uSystemLibrary.pas file with the above. You will now be able to use the Random and Random(ARange: Integer) methods.

1 Like

Thank you for the contribution, @Hagin_Michael. We will update this accordingly.

Hello,

I think there is again a problem of declaration in uSystemLibrary.pas is :

DefineMethod( 'Random',              0, tkFloat,   nil, RandomProc,            false, 1, 'ARange: integer' );

But I think that it should be to handle both with 1 and 0 argument :

DefineMethod( 'Random',              1, tkFloat,   nil, RandomProc,            false, 1, 'ARange: integer' );

We will include the fix in next release.