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>
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
Member Function Documentation
CoreExport void srand |
( |
DWORD32 |
seed |
) |
|
- Parameters:
- DWORD32 seed
The starting 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 [inline] |
{
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