Public Member Functions | Static Public Attributes

RandGenerator Class Reference

Search for all occurrences

Detailed Description

class RandGenerator

Description:
This class is available in release 4.0 and later only.

This class has interfaces for srand() and rand() methods of VC++ and other functions for random number generation. The srand() and rand() methods from stdlib.h have two main problems:

a) It's not satisfactorily random. The rand() function returns a pseudorandom integer in the range 0 to 0x7fff=32767. If we need a lot of random numbers using rand() (i.e. for generating 100,000 particles), we run out of continuity of random numbers. Generated random numbers becomes too discrete.

b) The rand() method is global function, not class object. Hence it is shared between all modules of your plug-in. Changes in one module may change randomness pattern in other independent module. To solve this contradiction, rand methods have to be implemented as a class object.

The RandGenerator does exactly that. It has much more random numbers: RAND_MAX = 0xFFFFFFFF = 4,294,967,295. Also, using instances of the class, it's much easier to create separate threads of random numbers for a specific module.

Data Members:
static const DWORD32 RAND_MAX

This definition is used to override the VC++ rand methods.

#include <randgenerator.h>

Inheritance diagram for RandGenerator:
Inheritance graph
[legend]

List of all members.

Public Member Functions

CoreExport  RandGenerator ()
CoreExport void  srand (DWORD32 seed)
CoreExport DWORD32  rand (void)
CoreExport int  RandSign (void)
CoreExport float  Rand01 (void)
CoreExport float  Rand11 (void)
CoreExport float  Rand55 (void)
CoreExport int  Rand0X (int maxnum)
const bool  Valid (void) const

Static Public Attributes

static CoreExport const DWORD32  RAND_MAX

Constructor & Destructor Documentation

CoreExport RandGenerator ( )
Remarks:
Constructor.

Member Function Documentation

CoreExport void srand ( DWORD32  seed )
Remarks:
This method sets the starting point for generating a series of pseudorandom integers. To reinitialize the generator, use 1 as the seed argument. Any other value for seed sets the generator to a random starting point. rand() retrieves the pseudorandom numbers that are generated. Calling rand() before any call to this method generates the same sequence as calling it with seed passed as 1.
Parameters:
DWORD32 seed

The starting seed.
CoreExport DWORD32 rand ( void  )
Remarks:
This method returns a pseudorandom integer in the range 0 to RAND_MAX
CoreExport int RandSign ( void  )
Remarks:
This method returns the random number sign, either -1 or 1.
CoreExport float Rand01 ( void  )
Remarks:
This method return a random number between 0.0f and 1.0f.
CoreExport float Rand11 ( void  )
Remarks:
This method return a random number between -1.0f and 1.0f.
CoreExport float Rand55 ( void  )
Remarks:
This method return a random number between -0.5f and 0.5f.
CoreExport int Rand0X ( int  maxnum )
Remarks:
This method return a random number between 0 and maxnum.
const bool Valid ( void  ) const [inline]
Remarks:
This method returns TRUE if the random number generator has been explicitly initialized by the srand() method.
                                        { 
            return m_explicitelyInitialized; 
        }

Member Data Documentation

CoreExport const DWORD32 RAND_MAX [static]

RandGenerator RandGenerator RandGenerator RandGenerator RandGenerator RandGenerator RandGenerator RandGenerator RandGenerator RandGenerator
RandGenerator RandGenerator RandGenerator RandGenerator RandGenerator RandGenerator RandGenerator RandGenerator RandGenerator RandGenerator