# Random number generator for even numbers only (500 points)

I need to quickly generate a random number between 1000 and 65000 but it must be even.

I am using Delphi 6.

I am giving the maximum 500 points as this is urgent.  Many thanks for your help.
###### Who is Participating?

Commented:
I think this is what you want:
``````function TForm1.RandEven: Integer;
begin
Randomize;
repeat
Result :=  (Random( 64000 ) + 1000);
UNtil (Result Mod 2) = 0

end;
``````
0

Author Commented:
SteveBay, many thanks for your help.  Greatly appreciated.
0

Commented:
Randomize;
numberwanted := Random(500 + random(32000)) * 2;

The randomize is needed to mix up the pseudo-random numbers generated by the time.

or for a variable even range:
``````function randomeven(min, max: double): double;
var range, tmp : double;
begin
Randomize;
if min > max then
begin
tmp := min;
min := max;
max := tmp;
end;
min := min / 2;
max := max / 2;
range := max - min;
randomeven := (min + Random * range) * 2;
end;
``````
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.