Common::GaRandomGenerator Class Reference

GaRandomGenerator class implements algorithm for generating 64-bits wide random unsigned integers and floating-point numbers. It takes care of architecture's endianness, but underlying CPU architecture must support floating-point by IEEE 754 standard. GaRandomGenerator class doesn't implement GaRandom interface. Primary purpose of this class is to provide service for generating random numbers for classes which implement GaRandom interface. More...

#include <D:/Temp/vs/gal/source/Random.h>

List of all members.

Public Member Functions

 GaRandomGenerator ()
 This constructor initialize random generator with current time as seed.
 GaRandomGenerator (unsigned long seed)
 This constructor initialize random generator with user-defined seed.
GAL_API void GACALL Generate (unsigned int &word1, unsigned int &word2)
 This method generates 64-bit wide unsigned integer, and stores it in word1 and word2 parameters.
GAL_API float GACALL GenerateFloat ()
 GeneratrFloat method generates single precision floating point number i interval (0, 1).
GAL_API double GACALL GenerateDouble ()
 GeneratrFloat method generates double precision floating point number i interval (0, 1).
GAL_API void GACALL Initalization (unsigned int seed)
 Initializes random generator with specified seed. Initialization method is called by constructor.

Private Attributes

unsigned int _buffer [2][GRP_BUFFER_SIZE]
 Buffers used to generate bits of random numbers.
int _positions [2]
 Stores current positions into buffer.
bool _littleEndian
 This attribute indicates endianness of architecture. If it is set to true, the architecture is little-endian, if the architecture is big-endian this attribute is set to false.


Detailed Description

GaRandomGenerator class implements algorithm for generating 64-bits wide random unsigned integers and floating-point numbers. It takes care of architecture's endianness, but underlying CPU architecture must support floating-point by IEEE 754 standard. GaRandomGenerator class doesn't implement GaRandom interface. Primary purpose of this class is to provide service for generating random numbers for classes which implement GaRandom interface.

This class has built-in synchronizator so it is allowed to use LOCK_OBJECT and LOCK_THIS_OBJECT macros with instances of this class. All public methods are thread-safe.


Constructor & Destructor Documentation

Common::GaRandomGenerator::GaRandomGenerator (  )  [inline]

This constructor initialize random generator with current time as seed.

Common::GaRandomGenerator::GaRandomGenerator ( unsigned long  seed  )  [inline]

This constructor initialize random generator with user-defined seed.

Parameters:
seed user-defined seed.


Member Function Documentation

void Common::GaRandomGenerator::Generate ( unsigned int &  word1,
unsigned int &  word2 
)

This method generates 64-bit wide unsigned integer, and stores it in word1 and word2 parameters.

This method is thread-safe.

Parameters:
word1 reference to variable which is used to store 32 least significant bits of generated integer.
word2 the reference to variable which is used to store 32 most significant bits of generated integer.

float Common::GaRandomGenerator::GenerateFloat (  ) 

GeneratrFloat method generates single precision floating point number i interval (0, 1).

This method is thread-safe.

Returns:
Method returns generated number.

double Common::GaRandomGenerator::GenerateDouble (  ) 

GeneratrFloat method generates double precision floating point number i interval (0, 1).

This method is thread-safe.

Returns:
Method returns generated number.

void Common::GaRandomGenerator::Initalization ( unsigned int  seed  ) 

Initializes random generator with specified seed. Initialization method is called by constructor.

This method is not thread-safe.

Parameters:
seed seed used to initialize generator.


Member Data Documentation

unsigned int Common::GaRandomGenerator::_buffer[2][GRP_BUFFER_SIZE] [private]

Buffers used to generate bits of random numbers.

Stores current positions into buffer.

This attribute indicates endianness of architecture. If it is set to true, the architecture is little-endian, if the architecture is big-endian this attribute is set to false.


The documentation for this class was generated from the following files:

Genetic Algorithm Library
Coolsoft Software Development