Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

RandomStream Class Reference

#include <RandomStream.h>

List of all members.

Public Member Functions

 RandomStream ()
 Default constructor.

 RandomStream (long)
 Constructor with a seed number.

long nextLong ()
 Returns a random integer number in the range [1,2^32-2].

double next ()
 Returns a random floating point number in the range (0,1).

double next (double)
 Returns a random floating point number in the range [0,max).

double next (double, double)
 Returns a random floating point number in the range [low,high].


Private Attributes

long lastZ
 Previous random number.


Static Private Attributes

const long modulus = 2147483647
 Constant = 2^31-1.


Constructor & Destructor Documentation

RandomStream::RandomStream  ) 
 

Default constructor.

This method uses the current machine time as the seed for the random number stream.

Definition at line 24 of file RandomStream.cpp.

References lastZ, and modulus.

RandomStream::RandomStream long  seed  ) 
 

Constructor with a seed number.

This method takes in a particular value for the stream's beginning value. Thus you can create the same stream of numbers using a particular seed value.

Definition at line 38 of file RandomStream.cpp.

References lastZ, and modulus.


Member Function Documentation

double RandomStream::next double  low,
double  high
 

Returns a random floating point number in the range [low,high].

Notice that this method can return values in the full range of low to high, including the endpoint values. If you attempt to pass in values where low > high, the numbers are automatically swapped to enforce low <= high.

Parameters:
low The minimum value of the random number.
high The maximum value of the random number.
Returns:
A random number in the range [low, high] inclusive.

Definition at line 92 of file RandomStream.cpp.

References modulus, and nextLong().

double RandomStream::next double  max  ) 
 

Returns a random floating point number in the range [0,max).

Notice that this method can return 0.0 but cannot return any number >= max (assuming that max is a positive value).

Parameters:
max The upper limit for the returned random number.
Returns:
A random number in the range [0,max).

Definition at line 78 of file RandomStream.cpp.

References modulus, and nextLong().

double RandomStream::next  ) 
 

Returns a random floating point number in the range (0,1).

Notice that neither 0.0 nor 1.0 can be returned by this method.

Returns:
A random number in the range (0,1).

Definition at line 66 of file RandomStream.cpp.

References modulus, and nextLong().

Referenced by Mover::impdiff(), Mover::solve(), and Box< Float >::subdivide().

long RandomStream::nextLong  ) 
 

Returns a random integer number in the range [1,2^32-2].

Use this method if you want to get a random number as a long integer value.

Returns:
A random number in the range [1,2^32-2].

Definition at line 52 of file RandomStream.cpp.

References lastZ, and modulus.

Referenced by next().


Member Data Documentation

long RandomStream::lastZ [private]
 

Previous random number.

Definition at line 20 of file RandomStream.h.

Referenced by nextLong(), and RandomStream().

const long RandomStream::modulus = 2147483647 [static, private]
 

Constant = 2^31-1.

Definition at line 18 of file RandomStream.cpp.

Referenced by next(), nextLong(), and RandomStream().


The documentation for this class was generated from the following files:
Generated on Mon Jun 28 15:03:02 2004 for Advanced Surface Library by doxygen 1.3.4