KSquare Utilities
KKB::RandomNumGenerator Class Reference

Represents one single random number generator. More...

#include <RandomNumGenerator.h>

Public Member Functions

 RandomNumGenerator ()
 
 RandomNumGenerator (long _seed)
 
 ~RandomNumGenerator ()
 
long Next ()
 

Detailed Description

Represents one single random number generator.

Rather than using the two global functions "lrand48" and "srand48" you can create an instance of this class that will provide the random sequence. The advantage is that you can control who has access to this sequence. That is you do not need to worry that some other code that you are calling is not also getting numbers from this sequence. This will allow you to guarantee the same sequence of numbers for the same seed.

Definition at line 20 of file RandomNumGenerator.h.

Constructor & Destructor Documentation

RandomNumGenerator::RandomNumGenerator ( )

Definition at line 25 of file RandomNumGenerator.cpp.

26 {
27 #if defined(WIN32)
28  _lrand48_sequence = 0x1234ABCD330E;
29 #else
30  _lrand48_sequence = 0x1234ABCD330ELLU;
31 #endif
32 }
kkint64 _lrand48_sequence
Definition: KKBaseTypes.cpp:32
RandomNumGenerator::RandomNumGenerator ( long  _seed)

Definition at line 35 of file RandomNumGenerator.cpp.

36 {
37  kkint64 seedMask = 65535;
38  _lrand48_sequence &= seedMask;
39  kkint64 upperBits = _seed;
40  upperBits <<= 16;
41  _lrand48_sequence |= upperBits;
42 }
__int64 kkint64
Definition: KKBaseTypes.h:90
kkint64 _lrand48_sequence
Definition: KKBaseTypes.cpp:32
RandomNumGenerator::~RandomNumGenerator ( )

Definition at line 45 of file RandomNumGenerator.cpp.

46 {
47 }

Member Function Documentation

long RandomNumGenerator::Next ( )

Definition at line 63 of file RandomNumGenerator.cpp.

64 {
65  _lrand48_sequence = ( ((a * _lrand48_sequence) & mask) + c ) % m;
66  return (long)(_lrand48_sequence >> 17);
67 }
kkint64 _lrand48_sequence
Definition: KKBaseTypes.cpp:32

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