We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,355 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

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

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.
2
Contributors
1
Reply
2 Hours
Discussion Span
2 Months Ago
Last Updated
37
Views
hambu
Newbie Poster
1 post since Feb 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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

cereal
Veteran Poster
1,146 posts since Aug 2007
Reputation Points: 344
Solved Threads: 223
Skill Endorsements: 22

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0599 seconds using 2.69MB