1,105,288 Community Members

How to generate random number in FreePascal between 1 and 1,000,000

hambu
Newbie Poster
1 post since Feb 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
0
 

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.
Member Avatar
cereal
Posting Virtuoso
1,710 posts since Aug 2007
Reputation Points: 461 [?]
Q&As Helped to Solve: 345 [?]
Skill Endorsements: 44 [?]
 
3
 

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

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article