home *** CD-ROM | disk | FTP | other *** search
- // %PARAMETERS = "CH11LIST C:\UT2004"
- //Identifies the package
- //CH11_02LIST.uc
-
- class CH11_02LIST extends Commandlet;
- function int Main(string Args)
- {
- //#1
- local int iRange, iRandom,
- iControl, iCount;
- local string szNumbers;
- local float rRadius, rArea,
- rRandom;
- iRange = 6; iRandom = 0;
- rRadius = 5; rArea = 0;
- rRandom = 0;
- iControl = 10; iCount = 0;
-
- log("*************");
- log(Chr(10)
- @ " CH111_02LIST Object attributes and Random number functions"
- $ Chr(10));
- // #1 Integer Rand()
- szNumbers = " ";
- //space before
-
- log(chr(13));
- //# generate random int without shift
- while(iCount < iControl){
- iRandom = Rand(iRange);
- szNumbers @= iRandom;
- iCount++;
- }
- log(" A - Random 0 - 5: " @ Chr(10) @ szNumbers);
-
- //# 2.1 random with shift
- //delete the string contents and set the counter back to zero
- szNumbers = " ";
- iCount = 0;
- while(iCount < iControl){
- iRandom = 1 + Rand(iRange);
- szNumbers @= iRandom;
- iCount++;
- }
- log(Chr(10) @ " B - Random integers shifted (1 - 6): "
- @ Chr(10) @ szNumbers);
- //# 3 Real Values
- //random float (real) values - no shift
- //delete the string contents and set the counter back to zero
- szNumbers = " ";
- iCount = 0;
- while(iCount < iControl){
- rRandom = FRand();
- szNumbers @= rRandom;
- iCount++;
- }
- log(Chr(10) @ " C - Random real values (raw) : " @ Chr(10)
- @ szNumbers);
-
- //#3.1
- szNumbers = " ";
- iCount = 0;
- //# 3.1 Real numbers shifted
- while(iCount < iControl){
- rRandom = (1000 * FRand());
- szNumbers @= rRandom;
- iCount++;
- }
- log(Chr(10) @ " D - Random real values (x 1000): " @ Chr(10)
- @ szNumbers);
-
- //#3.2
- szNumbers = " ";
- iCount = 0;
- //# Real numbers shifted and recast to integers
- while(iCount < iControl){
- iRandom = int(10000 * FRand());
- szNumbers @= iRandom;
- iCount++;
- }
- log(Chr(10) @ " E - Random recast as integers: " @ Chr(10) @ szNumbers);
-
- //#4 Calculate the area of a Circle using Pi
- log(Chr(10) @ " F - Area of a circle is Pi (" $
- Chr(227) $ ") times the square of the radius." );
- log(" " $ Chr(227) $ "R^2 where R = 5 and Chr(227) = " $ Pi $ " :");
- rArea = Pi * (rRadius** 2);
- log(" Circle area: " $ rArea);
-
- //#5 Determine whether a number exceeds max
- log(Chr(10) @ " G - Does the area exceed the integer limit:"
- @ MaxInt $ "?");
- if( rArea < MaxInt){
- log(" Circle area (" $ int(Ceil(rArea))
- $ ") lies within the integer range");
- }
-
- //#6 Real numbers from a range 23.4 - 32.4 shifted (x 1000)
- szNumbers = " ";
- iCount = 0;
-
- while(iCount < iControl - 5){
- rRandom = (1000 * RandRange(23.4, 32.4));
- szNumbers @= int(rRandom);
- iCount++;
- }
- log(Chr(10) @ " H - Random range 23.4 - 32.4 shifted (x 1000) : "
- @ Chr(10) @ szNumbers);
-
- return 0;
- }
-