C:/Musimathics_local/Musimat/MusimatChapter9/C090703c.cpp File Reference

#include "MusimatChapter9.h"

Go to the source code of this file.

Functions

 MusimatChapter9Section (C090703c)
Static Void para1 ()
Integer Random (Integer L, Integer U)
Static Void para2 ()


Function Documentation

MusimatChapter9Section ( C090703c   ) 

Definition at line 2 of file C090703c.cpp.

References para1(), and para2().

00002                                  {
00003 Print("*** Random Integer Numbers Scaled to an Arbitrary Range ***");
00004 /*****************************************************************************
00005 
00006 Random Integer Numbers Scaled to an Arbitrary Range
00007 
00008 *****************************************************************************/
00009         para1(); // Step into this function to continue.
00010         para2(); // Step into this function to continue.
00011 }

Static Void para1 (  ) 

Definition at line 13 of file C090703c.cpp.

00013                     {
00014 /*****************************************************************************
00015 We can adapt the Random() function to return integers within a specified 
00016 integer range. When a real value is converted to an integer, we truncate 
00017 (discard) the fractional part, leaving the integer part. For example,
00018 *****************************************************************************/
00019 
00020         Print("*** Example of Truncation ***");
00021         Real r = 3.14159;
00022         Print("Real r = ", r);
00023         Integer i = Integer(r);
00024         Print("Truncated = ", i);
00025 
00026 /*****************************************************************************
00027 prints 3. Truncation is equivalent to the floor function.
00028 
00029 Below is a method to generate integer random values over an integer range.
00030 *****************************************************************************/
00031 }

Static Void para2 (  ) 

Definition at line 40 of file C090703c.cpp.

References Random(), and x.

00040                     {
00041 /*****************************************************************************
00042 Note that I added 1.0 to the upper real boundary. Truncation of the random 
00043 result necessitates slightly increasing the top end of the range of choice. 
00044 For example, in order to choose a value in the integer range 0 to 9, we must 
00045 generate a random real value x that lies in the range 0.0 <= x < 10.0. This 
00046 gives an equal chance of obtaining an integer in the range 0 to 9.
00047 
00048 Here are ten values generated by this function over the interval [0,10].
00049 *****************************************************************************/
00050         Print("*** Example of Random Integer Values in the Interval [0,10] ***");
00051         IntegerList x;
00052 
00053         For ( Integer i = 0; i < 10; i = i + 1 )
00054                 x[i] = Random( 0, 10 );
00055 
00056         Print( x );
00057 
00058 }}

Integer Random ( Integer  L,
Integer  U 
)

Definition at line 33 of file C090703c.cpp.

References Random(), and x.

00033                                      {
00034         Real rL = L;                                                    // convert L to Real
00035         Real rU = U + 1.0;                                              // convert U to Real, add 1.0
00036         Real x = Random(rL, rU);                                // get a real random value
00037         Return( Integer(x));                                    // return it as an integer
00038 }


Generated on Fri Sep 8 23:11:08 2006 for Musimat Chapter 9 Code Examples by  doxygen 1.4.7