in Delphi Code Challenges ::
Delphi programming challenges / exercises are designed to help you refactor your old code to make it more efficient; get new ideas on how to code faster / better Delphi code; help you solve a particular Delphi programming task and of course: to have fun while coding in Delphi :)
Delphi programming challenges / exercises are designed to help you refactor your old code to make it more efficient; get new ideas on how to code faster / better Delphi code; help you solve a particular Delphi programming task and of course: to have fun while coding in Delphi :)
This time, your challenge is to code a custom Delphi procedure with the following signature:
procedure Randomizer(const maxValue : int64; var values : array of int64) ;
Randomizer takes 2 parameters. "Values" is an int64 open array. Your code must fill in the "values" array with unique random numbers from 1 to maxValue.
Read the full article to learn how to submit your solution to this Delphi Challenge: Unique Random Number Generator
To win, submit the fastest entry!
Related:


You should probably qualify the degree of “randomness” expected: a low quality “looks like random from a mile away” implementation will be much cheaper than a truly random implementation.
@Eric: I was going to suggest the same thing. Are we expected to just use the random methods built into Delphi (as per the link to Generating random numbers).
Of course I guess we should handle the case in which more numbers are requested than the range allowed. Seems that should be invalid too.
@Eric: The standard Delphi Randomize and Random functions would be ok.
@Jim: Note that the max random number is always Length(array) * 10. This comes from the preparation code in the challenge description.
This reminds me of an old joke.
function Random():int;
begin
Result:=3;
// number picked randomly,
// chosen by throw of dice.
end;
http://xkcd.com/221/
Alt-text: “RFC 1149.5 specifies 4 as the standard IEEE-vetted random number.”
@Zarko: I was also referring to making use of the unqualified randomness properties to take “shortcuts”.
f.i. instead of generating a random number in the whole range and checking its uniqueness, a different randomness version could split the range in segments and generate a number in each segment, thus eliminating the need for an explicit uniqueness validation. It would still look and be random, just with different randomness properties
@Eric: As long as no numbers are repeating and every time you run the procedure you do get different results (”looks” random) it’s ok.
Let’s see that code and how fast that would be…
If you call the routine multiple times you get a different set of numbers each time, if you restart the program at each run you will always get the same numbers. Should I resend it with a Randomize statement or am I good without it?
@Jim Murtha: Let’s say that you are good without the call to “Randomizer” – only for this challenge. In real world you would, of course, ensure that random numbers are randomly seeded.