home *** CD-ROM | disk | FTP | other *** search
/ UnrealScript Game Programming All in One / UnrealScriptGameProgrammingAllInOne.iso / UGPAIOListings / UGPAIOListingsCh11 / CH11LIST / Classes / CH11_02LIST.uc < prev    next >
Encoding:
Text File  |  2006-02-04  |  3.2 KB  |  112 lines

  1. // %PARAMETERS = "CH11LIST C:\UT2004"
  2. //Identifies the package
  3. //CH11_02LIST.uc
  4.  
  5. class CH11_02LIST extends Commandlet;
  6. function int Main(string Args)
  7. {
  8.   //#1
  9.   local int   iRange,   iRandom,
  10.               iControl, iCount;
  11.   local string szNumbers;
  12.   local float rRadius,  rArea,
  13.               rRandom;
  14.   iRange   = 6;   iRandom = 0;
  15.   rRadius  = 5;   rArea  = 0;
  16.   rRandom  = 0;
  17.   iControl = 10;  iCount = 0;
  18.  
  19.   log("*************");
  20.   log(Chr(10) 
  21.           @ " CH111_02LIST Object attributes and Random number functions"
  22.                                                        $ Chr(10));
  23.  // #1 Integer Rand()
  24.  szNumbers = "   ";
  25.  //space before
  26.  
  27.   log(chr(13));
  28.  //# generate random int without shift
  29.   while(iCount < iControl){
  30.     iRandom = Rand(iRange);
  31.     szNumbers @= iRandom;
  32.     iCount++;
  33.   }
  34.   log("  A - Random 0 - 5: " @ Chr(10) @ szNumbers);
  35.  
  36.  //# 2.1 random with shift
  37.  //delete the string contents and set the counter back to zero
  38.   szNumbers = "   ";
  39.   iCount = 0;
  40.   while(iCount < iControl){
  41.     iRandom = 1 + Rand(iRange);
  42.     szNumbers @= iRandom;
  43.     iCount++;
  44.   }
  45.   log(Chr(10) @ " B - Random integers shifted (1 - 6): "
  46.                                              @ Chr(10) @ szNumbers);
  47.   //# 3  Real Values
  48.   //random float (real) values - no shift
  49.   //delete the string contents and set the counter back to zero
  50.   szNumbers = "   ";
  51.   iCount = 0;
  52.   while(iCount < iControl){
  53.     rRandom = FRand();
  54.     szNumbers @= rRandom;
  55.     iCount++;
  56.   }
  57.   log(Chr(10) @ " C - Random real values (raw) : " @ Chr(10)
  58.                                                    @ szNumbers);
  59.  
  60.  //#3.1
  61.   szNumbers = "   ";
  62.   iCount = 0;
  63.   //# 3.1 Real numbers shifted
  64.   while(iCount < iControl){
  65.     rRandom = (1000 * FRand());
  66.     szNumbers @= rRandom;
  67.     iCount++;
  68.   }
  69.   log(Chr(10) @ " D  -  Random real values (x 1000): " @ Chr(10)
  70.                                                        @ szNumbers);
  71.   
  72.   //#3.2
  73.   szNumbers = "   ";
  74.   iCount = 0;
  75.   //# Real numbers shifted and recast to integers
  76.   while(iCount < iControl){
  77.     iRandom = int(10000 * FRand());
  78.     szNumbers @= iRandom;
  79.     iCount++;
  80.   }
  81.   log(Chr(10) @ " E -  Random recast as integers: " @ Chr(10) @ szNumbers);
  82.  
  83.   //#4 Calculate the area of a Circle using Pi
  84.   log(Chr(10) @ " F - Area of a circle is Pi (" $
  85.                        Chr(227) $ ") times the square of the radius." );
  86.   log("     " $ Chr(227) $ "R^2 where R = 5 and Chr(227) = " $ Pi $ " :");
  87.   rArea = Pi * (rRadius** 2);
  88.   log("     Circle area: " $ rArea);
  89.  
  90.   //#5 Determine whether a number exceeds max
  91.   log(Chr(10) @ " G - Does the area exceed the integer limit:"
  92.                                                 @ MaxInt $ "?");
  93.   if( rArea < MaxInt){
  94.   log("     Circle area (" $ int(Ceil(rArea)) 
  95.                            $ ") lies within the integer range");
  96.   }
  97.  
  98.   //#6 Real numbers from a range 23.4 - 32.4 shifted (x 1000) 
  99.   szNumbers = "   ";
  100.   iCount = 0;
  101.  
  102.   while(iCount < iControl - 5){
  103.     rRandom = (1000 * RandRange(23.4, 32.4));
  104.     szNumbers @= int(rRandom);
  105.     iCount++;
  106.   }
  107.   log(Chr(10) @ " H - Random range 23.4 - 32.4 shifted (x 1000) : "
  108.                                          @ Chr(10)  @ szNumbers);
  109.  
  110.   return 0;
  111. }
  112.