26 class KRandomSequence::Private
81 else if (lngSeed1 == 0)
87 d->lngSeed1 = -lngSeed1;
91 static const long sMod1 = 2147483563;
92 static const long sMod2 = 2147483399;
94 void KRandomSequence::Private::draw()
96 static const long sMM1 =
sMod1 - 1;
97 static const long sA1 = 40014;
98 static const long sA2 = 40692;
99 static const long sQ1 = 53668;
100 static const long sQ2 = 52774;
101 static const long sR1 = 12211;
102 static const long sR2 = 3791;
124 lngSeed1 = sA1 * ( lngSeed1 - k*sQ1) - k*sR1;
132 shuffleArray[j] = lngSeed1;
136 lngShufflePos = shuffleArray[0];
144 lngSeed1 = sA1 * ( lngSeed1 - k*sQ1 ) - k*sR1;
153 lngSeed2 = sA2 * ( lngSeed2 - k*sQ2 ) - k*sR2;
159 j = lngShufflePos / sDiv;
160 lngShufflePos = shuffleArray[j] - lngSeed2;
161 shuffleArray[j] = lngSeed1;
163 if ( lngShufflePos < 1 )
165 lngShufflePos += sMM1;
173 if ( d->lngSeed2 < 0 )
175 d->lngShufflePos +=
sMod2;
179 if ( d->lngSeed1 < 0 )
181 d->lngSeed1 +=
sMod1;
189 static const double finalAmp = 1.0 /
double(
sMod1 );
190 static const double epsilon = 1.2E-7;
191 static const double maxRand = 1.0 - epsilon;
195 if ( ( temp = finalAmp * d->lngShufflePos ) > maxRand )
211 return max ? (((
unsigned long) d->lngShufflePos) % max) : 0;
219 return (((
unsigned long) d->lngShufflePos) & 1);
unsigned long getLong(unsigned long max)
Get the next number from the pseudo-random sequence.
double getDouble()
Get the next number from the pseudo-random sequence.
void modulate(int i)
Modulate the random sequence.
int random()
Generates a uniform random number.
virtual ~KRandomSequence()
Standard destructor.
bool getBool()
Get a boolean from the pseudo-random sequence.
KRandomSequence(long lngSeed=0)
Creates a pseudo-random sequence based on the seed lngSeed.
KRandomSequence & operator=(const KRandomSequence &a)
Assignment.
A class to create a pseudo-random sequence.
void setSeed(long lngSeed=0)
Restart the sequence based on lngSeed.
static const int s_nShuffleTableSize