How to generate random number in Free Pascal between 1 and 1,000,000?

I have used a variable type as LongInt, Real, Integer, but there is always an RangeError.

But random number between 1 and 33,333 is working correctly.

Program Random;

var
  a: ...;

begin

a:=random(1000000);

end.

While waiting for more appropriate support, try to load randomize. This seems to work fine for me:

Program Test;

var
  num:longint;

begin
  randomize;
  num:=random(1000000);
  write(num, '');
  writeln;
end.

Source: http://www.freepascal.org/docs-html/rtl/system/randomize.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.