Main Page | Namespace List | Class Hierarchy | Compound List | File List | Namespace Members | Compound Members | File Members

Tausworthe Class Reference

#include <abkrand.h>

Inheritance diagram for Tausworthe:

Inheritance graph
[legend]
Collaboration diagram for Tausworthe:

Collaboration graph
[legend]
List of all members.

Public Member Functions

unsigned getSeed () const
const char * getLocIdent () const
unsigned getCounter () const
const VerbositygetVerbosity () const

Static Public Member Functions

unsigned getExternalSeed ()

Static Public Attributes

const double randTick = 1/(0xffffffff + 1.0)
 author="Mike Oliver"


Protected Member Functions

 Tausworthe (unsigned bufSize, unsigned Q, unsigned *preloads, unsigned seed=UINT_MAX, Verbosity verb=Verbosity("silent"))
 Tausworthe (unsigned bufSize, unsigned Q, unsigned *preloads, const char *locIdent, unsigned counterOverride=UINT_MAX, Verbosity verb=Verbosity("silent"))
 ~Tausworthe ()
unsigned _getRawUnsigned ()
double _getRawDouble ()

Protected Attributes

unsigned * _preloads
unsigned _seed
Verbosity _verb

Private Member Functions

unsigned _encryptWithSeed (unsigned clear)
void _encryptBufWithSeed ()
void _encryptBufMultipartiteSeed ()
unsigned _multmod (unsigned x, unsigned y)

Private Attributes

unsigned _bufferSize
unsigned _tauswortheQ
unsigned * _buffer
unsigned _cursor

Constructor & Destructor Documentation

Tausworthe::Tausworthe unsigned  bufSize,
unsigned  Q,
unsigned *  preloads,
unsigned  seed = UINT_MAX,
Verbosity  verb = Verbosity("silent")
[inline, protected]
 

Definition at line 164 of file abkrand.h.

References _buffer, _bufferSize, _encryptBufWithSeed(), _preloads, and _tauswortheQ.

00167             :RandomRoot(seed,verb), _bufferSize(bufSize),
00168              _tauswortheQ(Q), _preloads(preloads)
00169             {
00170             _buffer = new unsigned[bufSize];
00171             for(unsigned i=0; i!=bufSize; i++) _buffer[i]=0;
00172             _encryptBufWithSeed();
00173             }

Here is the call graph for this function:

Tausworthe::Tausworthe unsigned  bufSize,
unsigned  Q,
unsigned *  preloads,
const char *  locIdent,
unsigned  counterOverride = UINT_MAX,
Verbosity  verb = Verbosity("silent")
[inline, protected]
 

Definition at line 175 of file abkrand.h.

References _buffer, _bufferSize, _encryptBufMultipartiteSeed(), _preloads, and _tauswortheQ.

00179             :RandomRoot(locIdent,counterOverride, verb),
00180              _bufferSize(bufSize),_tauswortheQ(Q),
00181              _preloads(preloads)
00182             {
00183             _buffer = new unsigned[bufSize];
00184             for(unsigned i=0; i!=bufSize; i++) _buffer[i]=0;
00185             _encryptBufMultipartiteSeed();
00186             }

Here is the call graph for this function:

Tausworthe::~Tausworthe  )  [inline, protected]
 

Definition at line 188 of file abkrand.h.

References _buffer.

00188 {delete [] _buffer;}


Member Function Documentation

void Tausworthe::_encryptBufMultipartiteSeed  )  [private]
 

Definition at line 207 of file Tausworthe.cxx.

References _buffer, _bufferSize, _cursor, _preloads, RandomRoot::getCounter(), RandomRoot::getExternalSeed(), RandomRoot::getLocIdent(), MD5::getWord(), numToStr(), padding, and MD5::update().

Referenced by Tausworthe().

00208     {
00209     unsigned i;
00210     unsigned mask = 0xffffffff;
00211     unsigned setbit = 0x1;
00212     MD5 hashPool;
00213     unsigned extSeed=getExternalSeed();
00214     unsigned counter=getCounter();
00215 
00216     char numstr[9];
00217     numstr[8]=0;
00218     const char *numstrPtr=reinterpret_cast<const char*>(numstr);
00219     const char *padPtr=reinterpret_cast<const char*>(padding);
00220 
00221     numToStr(numstr,extSeed);
00222     hashPool.update(numstrPtr,false);
00223     numToStr(numstr,counter);
00224     hashPool.update(numstrPtr,false);
00225 
00226     hashPool.update(getLocIdent(),false);
00227     hashPool.update(padPtr,false); //make sure we *do* MD5 transforms
00228 
00229     unsigned IVlocal = hashPool.getWord(0);
00230 
00231     memcpy(_buffer,_preloads,_bufferSize*sizeof(unsigned));
00232 
00233     //Having preloaded the buffer with the noise above, we
00234     //now "encrypt" it in cipher-feedback mode.
00235 
00236     //The purpose of this is so that related seeds will not
00237     //produce results that depend on each other in any obvious way.
00238 
00239     for (i=0;i<_bufferSize;i++)
00240         {
00241         _buffer[i] ^= IVlocal;
00242         numToStr(numstr,_buffer[i]);
00243         hashPool.update(numstrPtr,false);
00244         hashPool.update(padPtr,false);
00245         IVlocal = hashPool.getWord(0);
00246         }
00247 
00248     //Now we make sure the 32 columns of bits are linearly
00249     //independent.  This is kind of overkill as the chance
00250     //of linear dependence is only 1 in 2^218, but it doesn't
00251     //really cost anything and everybody does it, so why not.
00252 
00253     for (i=0;i<sizeof(unsigned)*8;i++)
00254         {
00255         _buffer[i] &= mask;
00256         _buffer[i] |= setbit;
00257         mask <<= 1;
00258         setbit <<= 1;
00259         }
00260 
00261     _cursor=0;
00262 
00263     }

Here is the call graph for this function:

void Tausworthe::_encryptBufWithSeed  )  [private]
 

Definition at line 167 of file Tausworthe.cxx.

References _buffer, _bufferSize, _cursor, _encryptWithSeed(), _preloads, and initVector.

Referenced by Tausworthe().

00168     {
00169     unsigned i;
00170     unsigned mask = 0xffffffff;
00171     unsigned setbit = 0x1;
00172     unsigned IVlocal = _encryptWithSeed(initVector);
00173 //  cout << "IVlocal" << IVlocal << endl;
00174     memcpy(_buffer,_preloads,_bufferSize*sizeof(unsigned));
00175 
00176     //Having preloaded the buffer with the noise above, we
00177     //now "encrypt" it in cipher-feedback mode.  "Encrypt" is
00178     //in quotes because it's not intended to be secure and isn't
00179     //*quite* a permutation (although there's a decryption method
00180     //that would work 99.999% of the time).
00181 
00182     //The purpose of this is so that related seeds will not
00183     //produce results that depend on each other in any obvious way.
00184 
00185     for (i=0;i<_bufferSize;i++)
00186         {
00187         _buffer[i] ^= IVlocal;
00188         IVlocal = _encryptWithSeed(_buffer[i]);
00189         }
00190 
00191     //Now we make sure the 32 columns of bits are linearly
00192     //independent.  This is kind of overkill as the chance
00193     //of linear dependence is only 1 in 2^218, but it doesn't
00194     //really cost anything and everybody does it, so why not.
00195 
00196     for (i=0;i<sizeof(unsigned)*8;i++)
00197         {
00198         _buffer[i] &= mask;
00199         _buffer[i] |= setbit;
00200         mask <<= 1;
00201         setbit <<= 1;
00202         }
00203 
00204     _cursor=0;
00205     }

Here is the call graph for this function:

unsigned Tausworthe::_encryptWithSeed unsigned  clear  )  [private]
 

Definition at line 77 of file Tausworthe.cxx.

References _multmod(), and RandomRoot::_seed.

Referenced by _encryptBufWithSeed().

00078     {
00079 //    cout << "clear: " << clear << endl;
00080     unsigned initval = clear^_seed;
00081 //    cout << "initval" << initval << endl;
00082     unsigned runval = initval;
00083     runval = _multmod(runval,runval);
00084 //    cout << "runval-I" << runval << endl;
00085     runval = _multmod(runval,runval);
00086     runval = _multmod(runval,runval);
00087     runval = _multmod(runval,runval);
00088     runval = _multmod(runval,initval);
00089     return runval;
00090 
00091     }

Here is the call graph for this function:

double Tausworthe::_getRawDouble  )  [inline, protected]
 

Definition at line 217 of file abkrand.h.

References _getRawUnsigned(), and RandomRoot::randTick.

00217 {return randTick * _getRawUnsigned();}

Here is the call graph for this function:

unsigned Tausworthe::_getRawUnsigned  )  [inline, protected]
 

Definition at line 189 of file abkrand.h.

References _buffer, _bufferSize, _cursor, and _tauswortheQ.

Referenced by _getRawDouble().

00190         {
00191                 //the function is the genuine "raw" engine for the RNG
00192                     {
00193                     unsigned retval;
00194                     int otherPoint = _cursor-_tauswortheQ;
00195                     if (otherPoint<0)
00196                         otherPoint += _bufferSize;
00197                 
00198                 #if defined(__SUNPRO_CC)
00199                 //|| defined(__GNUC__)
00200                     /* SUN compiler doesn't use "mutable" */
00201                     retval = const_cast<unsigned*>(_buffer)
00202                           [const_cast<Tausworthe*>(this)->_cursor] ^=
00203                         const_cast<unsigned*>(_buffer)[otherPoint];
00204                     if (++(const_cast<Tausworthe*>(this)->_cursor) >= _bufferSize)
00205                         const_cast<Tausworthe*>(this)->_cursor=0;
00206                 
00207                 #else
00208                     retval = _buffer[_cursor] ^= _buffer[otherPoint];
00209                     if (++_cursor >= _bufferSize)
00210                         _cursor=0;
00211                 #endif
00212                 
00213                     return retval;
00214                     }
00215                 
00216         }

unsigned Tausworthe::_multmod unsigned  x,
unsigned  y
[private]
 

Definition at line 148 of file Tausworthe.cxx.

References addMod(), times5(), timesTwoTo16(), and trim().

Referenced by _encryptWithSeed().

00149 {
00150     unsigned lowerY = y &  0x0000ffff;
00151     unsigned upperY = y >> 16;
00152     unsigned lowerX = x &  0x0000ffff;
00153     unsigned upperX = x >> 16;
00154 
00155     unsigned upperProd = trim(upperX*upperY);
00156     unsigned upperTerm = trim(times5(upperProd)); //contrib to sum mod 2^32-5
00157     unsigned midProd1 = trim(lowerY*upperX);
00158     unsigned midTerm1 = trim(timesTwoTo16(midProd1));
00159     unsigned midProd2 = trim(upperY*lowerX);
00160     unsigned midTerm2 = trim(timesTwoTo16(midProd2));
00161     unsigned lowerProd = trim(lowerY*lowerX);
00162 
00163     return addMod(upperTerm,addMod(midTerm1,addMod(midTerm2,lowerProd)));
00164 
00165 }

Here is the call graph for this function:

unsigned RandomRoot::getCounter  )  const [inherited]
 

Definition at line 74 of file abkroot.cxx.

References SeedHandler::_counter, RandomRoot::_handler, SeedHandler::_isSeedMultipartite, and abkfatal.

Referenced by _encryptBufMultipartiteSeed().

00075     {
00076     abkfatal(_handler._isSeedMultipartite,"Can't call getLocIdent() "
00077                                           "with old-style seed");
00078     return _handler._counter;
00079     }

unsigned RandomRoot::getExternalSeed  )  [static, inherited]
 

Definition at line 62 of file abkroot.cxx.

References SeedHandler::_externalSeed.

Referenced by _encryptBufMultipartiteSeed().

00063     {
00064     return SeedHandler::_externalSeed;
00065     }

const char * RandomRoot::getLocIdent  )  const [inherited]
 

Definition at line 67 of file abkroot.cxx.

References RandomRoot::_handler, SeedHandler::_isSeedMultipartite, SeedHandler::_locIdent, and abkfatal.

Referenced by _encryptBufMultipartiteSeed().

00068     {
00069     abkfatal(_handler._isSeedMultipartite,"Can't call getLocIdent() "
00070                                           "with old-style seed");
00071     return _handler._locIdent;
00072     }

unsigned RandomRoot::getSeed  )  const [inline, inherited]
 

Definition at line 122 of file abkrand.h.

References RandomRoot::_handler, SeedHandler::_isSeedMultipartite, RandomRoot::_seed, and abkfatal.

00123             {
00124             abkfatal(!_handler._isSeedMultipartite,"can't use getSeed() "
00125                        "with multipartite seed");
00126             return _seed;
00127             }

const Verbosity& RandomRoot::getVerbosity  )  const [inline, inherited]
 

Definition at line 133 of file abkrand.h.

References RandomRoot::_verb.

00133 {return _verb;}


Member Data Documentation

unsigned* Tausworthe::_buffer [mutable, private]
 

Definition at line 160 of file abkrand.h.

Referenced by _encryptBufMultipartiteSeed(), _encryptBufWithSeed(), _getRawUnsigned(), Tausworthe(), and ~Tausworthe().

unsigned Tausworthe::_bufferSize [private]
 

Definition at line 158 of file abkrand.h.

Referenced by _encryptBufMultipartiteSeed(), _encryptBufWithSeed(), _getRawUnsigned(), and Tausworthe().

unsigned Tausworthe::_cursor [mutable, private]
 

Definition at line 161 of file abkrand.h.

Referenced by _encryptBufMultipartiteSeed(), _encryptBufWithSeed(), and _getRawUnsigned().

unsigned* Tausworthe::_preloads [protected]
 

Definition at line 218 of file abkrand.h.

Referenced by _encryptBufMultipartiteSeed(), _encryptBufWithSeed(), and Tausworthe().

unsigned RandomRoot::_seed [protected, inherited]
 

Definition at line 105 of file abkrand.h.

Referenced by _encryptWithSeed(), RandomRoot::getSeed(), and RandomRoot::RandomRoot().

unsigned Tausworthe::_tauswortheQ [private]
 

Definition at line 159 of file abkrand.h.

Referenced by _getRawUnsigned(), and Tausworthe().

Verbosity RandomRoot::_verb [protected, inherited]
 

Definition at line 106 of file abkrand.h.

Referenced by RandomRoot::getVerbosity(), and RandomRoot::RandomRoot().

const double RandomRoot::randTick = 1/(0xffffffff + 1.0) [static, inherited]
 

author="Mike Oliver"

Definition at line 48 of file abkroot.cxx.

Referenced by _getRawDouble().


The documentation for this class was generated from the following files:
Generated on Mon Apr 25 01:15:58 2005 for Parquete by doxygen 1.3.2