[ThinAir Home]
[Table of Contents]
[Generator Instantiations]
[Bad Pseudo-Random Number Generators]
9 Special Generators
9.1 DwyerRandGen
This class is derived from MultConModRandGen and based on an article
by Jerry Dwyer in CUJ [2]. The algorithm used in this generator
is supposedly immune to undefined effects of overflow in multiplications.
Although, the MultConModRandGen class is also immune to these
effects, its implementation is slower than Dwyer's. However, Dwyer's algorithm
limits the size of the multipliers to the square root of the modulus. The
constructor for this class has the following prototype:
- DwyerRandGen( unsigned long mult, unsigned long mod, size_rand seed )
-
The value of a (supplied by
mult
), the modulus m (supplied by
mod
), and an initial value for X0 (supplied by seed
). If
no value is given for seed
, a 1 is used.
In addition to the public interface, the DwyerRandGen class has a
protected interface for use by its derived classes:
- unsigned long Quotient( void ) const;
-
Returns the quotient obtained by dividing the
mod
by the mult
.
- unsigned long Remainder( void ) const;
-
Returns the remainder obtained by dividing the
mod
by the mult
.
Dwyer's article listed four specific generators using his algorithm. These have
been implemented as Dwyer1RandGen, Dwyer2RandGen,
Dwyer3RandGen, and Dwyer4RandGen. All of these generators and
their base class are implemented in the files rnddwyer.h and
rnddwyer.cpp.
9.2 CompilerRandGen
All C/C++ compilers come with a PRNG implemented in their standard library. The
CompilerRandGen class allows access to this generator through the
interface specified by RandomGenerator. The CompilerRandGen
class is derived from RandomGenerator and is implemented in
the files randcomp.h and randcomp.cpp. The constructor for this
class has the following prototype:
- explicit CompilerRandGen( size_rand seed )
-
Requires a
seed
value. This seed
defaults to 1 if none is
supplied.
In addition to the public interface, the CompilerRandGen class has a
protected interface for use by its derived classes.
- size_rand Seed( void ) const;
-
Returns the initial seed value used when the current
generator was created.
- void SetSeed( size_rand seed );
-
Sets the initial seed value used when the current generator was created.
9.3 SHACtrRandGen
The SHACtrRandGen generator uses a counter to provide a variable
source of numbers for use by the SHARandGen algorithm. The
SHACtrRandGen class is derived from the SHARandGen class and
is implemented in the files randsha.h and randsha.cpp. The
constructors for this class have the following prototypes:
- SHACtrRandGen( unsigned short size, const char *seedStr, size_rand seed )
-
Requires a buffer of data that the object uses as part of the message in
the SHA algorithm. The length of the supplied buffer is
size
and
seedStr
points to the data. The constructor makes a copy of the data
for the object's use. The initial value for the counter is supplied by
seed
. The default value for seed
is 0.
- explicit SHACtrRandGen( const char *seedStr, size_rand seed )
-
Simplifies the construction of a SHACtrRandGen object by allowing a
null-terminated string as its argument. The argument
seedStr
has a
default value of ``SHAPRNG''. The initial value for the counter is supplied
by seed
. The default value for seed
is 0.
With many PRNGs, knowledge of the algorithm and a few consecutive numbers are
enough to duplicate the rest of the pseudo-random number sequence. The output
of the SHACtrRandGen generator should not be analyzable in this
fashion.
9.4 SHARngRandGen
The SHARngRandGen generator uses a PRNG supplied at construction time
to provide a variable source of numbers for use by the SHARandGen
algorithm. The SHARngRandGen class is derived from the
SHARandGen class and is implemented in the files randsha.h and
randsha.cpp. The constructors for this class have the following
prototypes:
- SHARngRandGen( unsigned short size, const char *seedStr, RandomGenerator *pRNG )
-
Requires a buffer of data that the object uses as part of the message
in the SHA algorithm. The length of the supplied buffer is
size
and
seedStr
points to the data. The constructor makes a copy of the data
for the object's use. The constructor also requires a pointer to a
heap-based PRNG object. The SHARngRandGen object owns this PRNG and
delete
s it when the object is destroyed.
- SHARngRandGen( const char *seedStr, RandomGenerator *pRNG )
-
Simplifies the construction of a SHARngRandGen object by allowing a
null-terminated string as one of its argument. The constructor also requires
a pointer to a heap-based PRNG object. The SHARngRandGen object
owns this PRNG and
delete
s it when the object is destroyed.
With many PRNGs, knowledge of the algorithm and a few consecutive numbers are
enough to duplicate the rest of the pseudo-random number sequence. The output
of the SHARngRandGen generator should not be analyzable in this
fashion.
For further information, contact G. Wade Johnson
(gwadej@anomaly.org).
© 1997 G. Wade Johnson.
All rights reserved.
http://www.anomaly.org/ThinAir/specials.html