Question: Harry Stockx's Entry for the Unique Random Numbers Generator
Challenge: a custom Delphi function, Randomizer, takes an open integer array and should fill it with unique random numbers as fast as possible.
The code is submitted for the Unique Random Numbers Delphi Challenge
Answer: Unique random number generator entry by Harry Stockx (The Netherlands):
- array size: 10 000
- number range: 1 - 100 000
procedure Randomizer_Harry_Stockx(Const MaxValue : int64; var Values : array of int64) ;
var
Current : int64;
function Unique(Value : int64): boolean;
var j : int64;
begin
j:=0;
while (J < Current) and (Values[j] <> Value) do Inc(j) ;
Result := J = Current;
if Result then Values[Current] := Value;
end;
begin
Current:=0;
while (Current<= High(Values)) do
if (Unique(1+Random(MaxValue))) then Inc(Current) ;
end;
Test data:- array size: 10 000
- number range: 1 - 100 000
Herry's speed result: 400 milliseconds.
Explore the list of all accepted entries for the Fastest Unique Random Number Generator Delphi challenge.

