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>
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 . |
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.
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.
seed | user-defined seed. |
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.
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.
double Common::GaRandomGenerator::GenerateDouble | ( | ) |
GeneratrFloat
method generates double precision floating point number i interval (0, 1).
This method is thread-safe.
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.
seed | seed used to initialize generator. |
unsigned int Common::GaRandomGenerator::_buffer[2][GRP_BUFFER_SIZE] [private] |
Buffers used to generate bits of random numbers.
int Common::GaRandomGenerator::_positions[2] [private] |
Stores current positions into buffer.
bool Common::GaRandomGenerator::_littleEndian [private] |
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
.