iFocus.Life News News - Breaking News & Top Stories - Latest World, US & Local News,Get the latest news, exclusives, sport, celebrities, showbiz, politics, business and lifestyle from The iFocus.Life,

Hrvoje Brozović"s Entry for the Unique Random Numbers Generator

106 52
Question: Hrvoje Brozovic'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 Hrvoje Brozovic (Croatia):

procedure Randomizer_Hrvoje_Brozovic( const maxValue : int64; var values: array of int64 ) ; var cnt: integer;     i_random: int64;     ab_table: array of boolean; begin   SetLength( ab_table, maxValue ) ;   for cnt := Low(values) to High(values) do   begin     while true do     begin       i_random := Random(maxValue);       if not ab_table[i_random] then       begin         values[cnt] := i_random;         ab_table[i_random] := true;         break;       end;     end;   end; end;

Test data:
- array size: 10 000
- number range: 1 - 100 000
Marius's speed result: 353 microseconds.

Explore the list of all accepted entries for the Fastest Unique Random Number Generator Delphi challenge.
Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time
You might also like on "Technology"

Leave A Reply

Your email address will not be published.