- Main Page
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Members

# Random Class Reference

Random class provides a set of Real and Integer linear congruential random operations. More...

`#include <Random.h>`

List of all members.

## Public Member Functions
| Random (Integer a=16807, Integer b=0, Integer c=2147483647)
| 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

Random class provides a set of Real and Integer linear congruential random operations.

Note, this implementation does not produce very high-quality randomness. The methods here are good for understanding general principles, but for better numerical results see Press, et. al., "Numerical Recipes in C", Cambridge University Press, 1988.

Definition at line 29 of file Random.h.

## Constructor & Destructor Documentation

Random::Random | ( | Integer | a = `16807`,
|  | Integer | b = `0`,
|  | Integer | c = `2147483647` |
| ) |  |  | `[inline]`

Default constructor. Initialization constants from Park and Miller.

Definition at line 34 of file Random.h.

    00034 : 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().

    00043 {
    00044         Return( Integer(time(0)) );  // time_t
    00045 }

Integer Random::lCRandom | ( |  | ) | `[inline]`

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

Definition at line 37 of file Random.h.

References If, and Return.

Referenced by LCRandom(), and random().

    00037                             {
    00038                 m_x = mod( m_a * m_x + m_b, m_c );      // update x based on its previous value
    00039                 Integer r = m_x;
    00040                 If ( r < 0 )                                            // force the result to be positive
    00041                         r = -r;
    00042                 Return( r );
    00043         }

Integer Random::random | ( | Integer | L,
|  | Integer | U |
| ) |  |  | `[inline]`

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

Parameters:

  | L | Lower bound
  | U | Upper bound

Returns:
  Random Integer value

Definition at line 59 of file Random.h.

References random(), and Return.

    00059                                                {
    00060                 Real i = random( Real( L ), U + 1.0 );
    00061                 Return( Integer( i ) );
    00062         }

Real Random::random | ( | Real | L,
|  | Real | U |
| ) |  |  | `[inline]`

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

Parameters:

  | L | Lower bound
  | U | Upper bound

Returns:
  Random Real value

Definition at line 49 of file Random.h.

References lCRandom(), and Return.

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

    00049                                       {
    00050                 Real r = lCRandom();
    00051                 r = r / Real( m_c );
    00052                 Return( r * ( U - L ) + L );
    00053         }

Integer Random::seed | ( | Integer | s | ) | `[inline]`

Return old random seed, set new seed.

Parameters:

  | s | New Integer seed

Returns:
  Old Integer seed

Definition at line 67 of file Random.h.

References Return.

Referenced by SeedRandom().

    00067                                   {
    00068                 Integer r = m_x;
    00069                 m_x = s;
    00070                 Return( r );
    00071         }

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

- C:/Musimathics_local/Musimat/include/Random.h
- C:/Musimathics_local/Musimat/MusimatLib/Random.cpp