I converted a C routine to Pascal via CodeConvert. It uses generics which I don't necessarily need but thought this might be a chance to learn about them. I got to the point below but now get an error in the last line where the array should be sorted - "Syntax Error, Create expected but Sort found".

I am a bit lost here. I assume CodeConvert put the TArray in as placeholder for some sort of generic array. The docs say TArray (under sysutils) is "not needed in Free Pascal, where 2 array types are equal if their element types are equal." WTF ? And why in sysutils? Is there another TArray in Generics.Collection I should use ?

Maybe remove sysutils from the uses clause - aha, now the error message changes to "Generics without specialization cannot be used as a type for variables". That seems to make more sense but I can't get the specialization right. I beg for a hint.

function count_repeats(var rng: TRandom; expanse: SizeInt): SizeInt;

type

rngval_t = Integer; // Assuming RNG_TYPE::result_type is an Integer

var

values: specialize TArray<rngval_t>;

prev, curr: rngval_t;

i, duplicates: SizeInt;

begin

// Allocate an array to hold all the output.

SetLength(values, expanse);

Values := specialize TArray <integer>.Create;

// Store all the output from the generator.

for i := 0 to expanse - 1 do

values[i] := rng.Next; // Assuming rng() is equivalent to rng.Next

// Sort the array

TArray.Sort<rngval_t>(values);