Dorin Duminica"s Entry for the Unique Random Numbers Generator
Question: Dorin Duminica'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 Dorin Duminica (Romania):
Test data:
- array size: 10 000
- number range: 1 - 100 000
Dorin's speed result: 625 milliseconds.
Explore the list of all accepted entries for the Fastest Unique Random Number Generator Delphi challenge.
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 Dorin Duminica (Romania):
procedure Randomizer_Dorin_Duminica(const maxValue: int64; var values: array of int64) ; var index: int64; tmpValue: Int64; function ValueExists(const AValue: Int64): Boolean; var k: int64; begin Result := True; k := Low(values) ; while k < High(values) do begin if values[k] = AValue then Exit; k := k + 1; end; Result := False; end; begin index := low(values) ; while index < High(Values) do begin tmpValue := random(maxValue) mod (maxValue or index) ; while ValueExists(tmpValue) do tmpValue := random(maxValue) mod (maxValue or index) ; values[index] := tmpValue; index := index +1; end; end;
Test data:
- array size: 10 000
- number range: 1 - 100 000
Dorin's speed result: 625 milliseconds.
Explore the list of all accepted entries for the Fastest Unique Random Number Generator Delphi challenge.