3ds Max C++ API Reference
RandGenerator Class Reference

class RandGenerator More...

#include <randgenerator.h>

+ Inheritance diagram for RandGenerator:

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
 

Additional Inherited Members

- Static Public Member Functions inherited from MaxHeapOperators
static UtilExport voidoperator new (size_t size)
 Standard new operator used to allocate objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e)
 Standard new operator used to allocate objects if there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new (size_t size, const char *filename, int line)
 New operator used to allocate objects that takes the filename and line number where the new was called If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, int block_type, const char *filename, int line)
 New operator used to allocate objects that takes the type of memory, filename and line number where the new was called If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e, const char *filename, int line)
 New operator used to allocate objects that takes the filename and line number where the new was called If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new (size_t size, unsigned long flags)
 New operator used to allocate objects that takes extra flags to specify special operations If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e, unsigned long flags)
 New operator used to allocate objects that takes extra flags to specify special operations If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size, const char *filename, int line)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, int block_type, const char *filename, int line)
 New operator used to allocate arrays of objects. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e, const char *filename, int line)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size, unsigned long flags)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e, unsigned long flags)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport void operator delete (void *ptr)
 Standard delete operator used to deallocate an object If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e)
 Standard delete operator used to deallocate an object If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete (void *ptr, const char *filename, int line)
 Delete operator used to deallocate an object that takes the filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, int block_type, const char *filename, int line)
 Delete operator used to deallocate an object that takes the type of memory, filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e, const char *filename, int line)
 Delete operator used to deallocate an object that takes the filename and line number where the delete was called If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete (void *ptr, unsigned long flags)
 Delete operator used to deallocate an object that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e, unsigned long flags)
 Delete operator used to deallocate an object that takes extra flags to specify special operations If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr)
 Standard delete operator used to deallocate an array of objects If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e)
 Standard delete operator used to deallocate an array of objects If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, int block_type, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the type of memory, filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the filename and line number where the delete was called If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr, unsigned long flags)
 Delete operator used to deallocate an array of objects that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e, unsigned long flags)
 Delete operator used to deallocate an array of objects that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, void *placement_ptr)
 Placement new operator. More...
 
static UtilExport void operator delete (void *ptr, void *placement_ptr)
 Placement delete operator. More...
 
static UtilExport voidaligned_malloc (size_t size, size_t alignment)
 Allocates memory on a specified alignment boundary. More...
 
static UtilExport voidaligned_realloc (void *ptr, size_t size, size_t alignment)
 Reallocates memory on a specified alignment boundary. More...
 
static UtilExport void aligned_free (void *ptr)
 Frees a block of memory that was allocated with aligned_malloc/aligned_realloc. More...
 

Detailed Description

class RandGenerator

Description:
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.

Constructor & Destructor Documentation

◆ RandGenerator()

Remarks
Constructor.

Member Function Documentation

◆ srand()

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.

◆ rand()

CoreExport DWORD32 rand ( void  )
Remarks
This method returns a pseudorandom integer in the range 0 to RAND_MAX

◆ RandSign()

CoreExport int RandSign ( void  )
Remarks
This method returns the random number sign, either -1 or 1.

◆ Rand01()

CoreExport float Rand01 ( void  )
Remarks
This method return a random number between 0.0f and 1.0f.

◆ Rand11()

CoreExport float Rand11 ( void  )
Remarks
This method return a random number between -1.0f and 1.0f.

◆ Rand55()

CoreExport float Rand55 ( void  )
Remarks
This method return a random number between -0.5f and 0.5f.

◆ Rand0X()

CoreExport int Rand0X ( int  maxnum)
Remarks
This method return a random number between 0 and maxnum.

◆ Valid()

const bool Valid ( void  ) const
inline
Remarks
This method returns TRUE if the random number generator has been explicitly initialized by the srand() method.
111  {
112  return m_explicitelyInitialized;
113  }

Member Data Documentation

◆ RAND_MAX

CoreExport const DWORD32 RAND_MAX
static