Functions

/Users/garethloy/Musimathics/Musimat1.2/MusimatChapter9/C090703b.cpp File Reference

#include "MusimatChapter9.h"

Go to the source code of this file.

Functions

 MusimatChapter9Section (C090703b)
Real luRandom (Real L=0.0, Real U=1.0)
Static Void para1 ()

Function Documentation

Real luRandom ( Real  L = 0.0,
Real  U = 1.0 
)

Definition at line 19 of file C090703b.cpp.

References c().

                                          {
        Static Const Integer c = Musimat_Random_Seed; // defined in Random.h
        Integer i = LCRandom();                 // get a random integer value
        Real r = Real(i);                               // convert it to a real value
        r = r/Real(c);                                  // scale it to 0.0 <= r < 1.0
        Return(r * (U - L) + L);                // scale it to the range L to U
}
MusimatChapter9Section ( C090703b   )

Definition at line 2 of file C090703b.cpp.

References para1().

                                 {
        Print("*** Random Real Numbers ***");
        /*****************************************************************************
         
         Random Real Numbers
         
         The LCRandom() method returns integers between 0 and c. It is straightforward 
         to map its output to any range of Real values between an upper bound U and a 
         lower bound L, as shown in the Random function, below.
         *****************************************************************************/
        para1(); // Step into this function to continue.
}
Static Void para1 (  )

Definition at line 27 of file C090703b.cpp.

References luRandom().

                    {
        /*****************************************************************************
         First, we use LCRandom() to get a random integer. Recall that LCRandom() 
         forces the result to be positive. We promote its random integer result to 
         Real and store it in r. Next, we divide it by c so its range is 0.0 <= r < 1.0. 
         Finally, we scale it by the difference between U and L, and add L, so that 
         the random value is bounded above by U and below by L. That way we can get 
         a random result from a particular range of values that we can stipulate.
         
         Here is an example of invoking this Real Random() method:
         *****************************************************************************/
        
        Print("*** Ten invocations of luRandom() ***");
        RealList x;
        
        For (Integer i = 0; i < 10; i++ ) {
                x[i] = luRandom(0.0, 1.0);
        }
        
        Print( x );
        
        /*****************************************************************************
         luRandom() is declared above with initializing values for its
         two arguments. This means luRandom() can be called with 0, 1, or 2 arguments.
         If called with zero arguments, both initial values are employed; if called with one
         argument, only the second initial value is employed; if called with two arguments,
         the initial values are ignored.
         Initial value for L defaults to 0.0, and U defaults to 1.0.  Thus, to
         get a number in the unsigned unit interval [0,1), it suffices to invoke 
         luRandom() without arguments, as follows:
         *****************************************************************************/
        Print("*** Various Calls to luRandom() ***");
        Real r = luRandom();
        Print(r);
        Print("luRandom(37.5, 37.9)=", luRandom(37.5, 37.9));
        
}