Living Lazarus
Monday, October 09, 2006
 
RandomRange function

Delphi has a great function that Lazarus lacks; the ability to return a random number within a set range. However, this little function will do the job really well.

Declare the following in the public section,

function RandomRange(aMin: Integer; aMax: Integer) : Integer;

Now add this to your implementation section

function TForm1.RandomRange(aMin: Integer; aMax: Integer) : Integer;
begin
RandomRange := Random(aMax-aMin) + aMin ;
end;


Usage is very simple,

declare a variable, say aNum and then use like this,

aNum := RandomRange(10,100);

Simple.

 
Comments: Post a Comment



<< Home
One mans exploration into the possibilities of an open source RAD

Name:
Location: Townshend, Hayle, Cornwall, United Kingdom
ARCHIVES
September 2006 / October 2006 / November 2006 / April 2007 / July 2007 / November 2007 / May 2008 / September 2009 / March 2011 / January 2013 /


Powered by Blogger