osgEarth 2.1.1
Public Types | Public Member Functions | Private Attributes

osgEarth::Random Class Reference

List of all members.

Public Types

enum  Method { METHOD_FAST }

Public Member Functions

 Random (Method method=METHOD_FAST)
 Random (unsigned seed, Method method=METHOD_FAST)
 Random (const Random &rhs)
void reset ()
unsigned next (unsigned mod)
double next ()

Private Attributes

Method _method
unsigned _seed
unsigned _next

Detailed Description

Psuedo random number generator. Results are guaranteed to be consistent across machines given the same seed value.

Definition at line 30 of file Random.


Member Enumeration Documentation

Enumerator:
METHOD_FAST 

Definition at line 33 of file Random.

        {
            METHOD_FAST        // not great, but super-fast and cheap.
        };

Constructor & Destructor Documentation

Random::Random ( Random::Method  method = METHOD_FAST)

Constructs a new random number generator. It is seeded with the system clock.

Parameters:
methodRNG method to use

Definition at line 41 of file Random.cpp.

                                    :
_method( method ),
_seed  ( (unsigned)::time(0L) )
{
    _next = _seed;
}
Random::Random ( unsigned  seed,
Random::Method  method = METHOD_FAST 
)

Constucts a new random number generator with a user-specified seed. The results are guaranteed to be globally consistent.

Parameters:
seedRNG seed value
methodRNG method to use

Definition at line 48 of file Random.cpp.

                                                   :
_method( method ),
_seed  ( seed == 0 ? (unsigned)::time(0L) : seed ) // seed=0 => time-based
{
    _next = _seed;
}
Random::Random ( const Random rhs)

Copy constructor.

Definition at line 55 of file Random.cpp.

                                  :
_method( rhs._method ),
_seed  ( rhs._seed ),
_next  ( rhs._next )
{
    //nop
}

Member Function Documentation

unsigned Random::next ( unsigned  mod)

Gets the next random number as an unsigned int.

Parameters:
modModulus value. The result will fall within the range [0..mod)

Definition at line 70 of file Random.cpp.

{
    if ( _method == METHOD_FAST )
    {
        fast_rand( _next );
    }    
    return mod == UINT_MAX ? _next : _next % mod;
}

Here is the call graph for this function:

Here is the caller graph for this function:

double Random::next ( )

Gets the next random number as a double in the range [0..1].

Definition at line 80 of file Random.cpp.

{
    return (double)next(UINT_MAX) / (double)UINT_MAX;
}
void Random::reset ( )

Resets the PRNG to its initial state (initial seed).

Definition at line 64 of file Random.cpp.

{
    _next = _seed;
}

Member Data Documentation

Definition at line 76 of file Random.

unsigned osgEarth::Random::_next [private]

Definition at line 78 of file Random.

unsigned osgEarth::Random::_seed [private]

Definition at line 77 of file Random.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines