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

#include "MusimatChapter9.h"

Go to the source code of this file.

Functions

 MusimatChapter9Section (C090703b)
Real Random (Real L, Real U)
Static Void para1 ()


Function Documentation

MusimatChapter9Section ( C090703b   ) 

Definition at line 2 of file C090703b.cpp.

References para1().

00002                                  {
00003 Print("*** Random Real Numbers ***");
00004 /*****************************************************************************
00005 
00006 Random Real Numbers
00007 
00008 The LCRandom() method returns integers between 0 and c. It is straightforward 
00009 to map its output to any range of Real values between an upper bound U and a 
00010 lower bound L, as shown in the Random function, below.
00011 *****************************************************************************/
00012         para1(); // Step into this function to continue.
00013 }

Static Void para1 (  ) 

Definition at line 22 of file C090703b.cpp.

References Random(), and x.

00022                     {
00023 /*****************************************************************************
00024 First, we use LCRandom() to get a random integer. Recall that LCRandom() 
00025 forces the result to be positive. We promote its random integer result to 
00026 Real and store it in r. Next, we divide it by c so its range is 0.0 <= r < 1.0. 
00027 Finally, we scale it by the difference between U and L, and add L, so that 
00028 the random value is bounded above by U and below by L. That way we can get 
00029 a random result from a particular range of values that we can stipulate.
00030 
00031 Here is an example of invoking this Real Random() method:
00032 *****************************************************************************/
00033 
00034         Print("*** Ten invocations of Real Random() ***");
00035         RealList x;
00036         
00037         For (Integer i = 0; i < 10; i++ )
00038                 x[i] = Random(0.0, 1.0);
00039 
00040         Print( x );
00041 
00042 /*****************************************************************************
00043 This function is declared in MusimatChapter9.h with default values for its
00044 two arguments such that L defaults to 0.0 and U defaults to 1.0.  Thus, to
00045 get a number in the unsigned unit interval [0,1), it suffices to invoke 
00046 Random() without arguments, as follows:
00047 *****************************************************************************/
00048         Print("*** Various Calls to Real Random() ***");
00049         Real r = Random();
00050         Print(r);
00051         Print("Random(37.5, 37.9)=", Random(37.5, 37.9));
00052 
00053 }}

Real Random ( Real  L,
Real  U 
)

Definition at line 15 of file C090703b.cpp.

00015                             {
00016         Integer i = LCRandom();                 // get a random integer value
00017         Real r = Real(i);                               // convert it to a real value
00018         r = r/Real(c);                                  // scale it to 0.0 <= r < 1.0
00019         Return(r * (U - L) + L);                // scale it to the range L to U
00020 }


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