#include <Random.h>
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. | |
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.
| Integer Random::getTime | ( | ) |
| Integer Random::lCRandom | ( | ) | [inline] |
Linear congruential method of random number generation. See Knuth, "Seminumerical Methods".
Definition at line 37 of file Random.h.
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 }
Return a random value as a Real within a range of Reals.
| L | Lower bound | |
| U | Upper bound |
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 }
1.4.7