Public Member Functions

Random Class Reference

#include <Random.h>

List of all members.

Public Member Functions

 Random (Integer a=16807, Integer b=0, Integer c=Musimat_Random_Seed)
 Default constructor. Initialization constants from Park and Miller.
Integer lCRandom ()
 Linear congruential method of random number generation. See Knuth, "Seminumerical Methods".
Real random (Real L, Real U)
 Return a random value as a Real within a range of Reals.
Integer random (Integer L, Integer U)
 Return a random value as a Real within a range of Reals.
Integer seed (Integer s)
 Return old random seed, set new seed.
Integer getTime ()
 Return number of seconds since epoch.

Detailed Description

Definition at line 32 of file Random.h.


Constructor & Destructor Documentation

Random::Random ( Integer  a = 16807,
Integer  b = 0,
Integer  c = Musimat_Random_Seed 
) [inline]

Default constructor. Initialization constants from Park and Miller.

Definition at line 37 of file Random.h.

: m_a(a), m_b(b), m_c(c) { m_x = 1; }

Member Function Documentation

Integer Random::getTime (  )

Return number of seconds since epoch.

Used to automatically obtain fluctuating random sequences.

Returns:
Time in seconds since the epoch.

Definition at line 42 of file Random.cpp.

References Return.

Referenced by Time().

{
        Return( Integer(time(0)) );  // time_t
}
Integer Random::lCRandom (  ) [inline]

Linear congruential method of random number generation. See Knuth, "Seminumerical Methods".

Definition at line 40 of file Random.h.

References If, and Return.

Referenced by LCRandom(), and random().

                            {
                m_x = mod( m_a * m_x + m_b, m_c );      // update x based on its previous value
                Integer r = m_x;
                If ( r < 0 )                                            // force the result to be positive                                                      
                        r = -r; 
                Return( r ); 
        }
Real Random::random ( Real  L,
Real  U 
) [inline]

Return a random value as a Real within a range of Reals.

Parameters:
LLower bound
UUpper bound
Returns:
Random Real value

Definition at line 52 of file Random.h.

References lCRandom(), and Return.

Referenced by IRandom(), Random(), and random().

                                      {
                Real r = lCRandom();
                r = r / Real( m_c );
                Return( r * ( U - L ) + L );
        }
Integer Random::random ( Integer  L,
Integer  U 
) [inline]

Return a random value as a Real within a range of Reals.

Parameters:
LLower bound
UUpper bound
Returns:
Random Integer value

Definition at line 62 of file Random.h.

References random(), and Return.

                                               {
                Real i = random( Real( L ), U + 1.0 );
                Return( Integer( i ) );
        }
Integer Random::seed ( Integer  s ) [inline]

Return old random seed, set new seed.

Parameters:
sNew Integer seed
Returns:
Old Integer seed

Definition at line 70 of file Random.h.

References Return.

Referenced by SeedRandom().

                                  {
                Integer r = m_x;
                m_x = s;
                Return( r );
        }

The documentation for this class was generated from the following files: