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

random.h

Go to the documentation of this file.
00001 /*
00002  * random.h
00003  *
00004  * ISAAC random number generator by Bob Jenkins.
00005  *
00006  * Portable Windows Library
00007  *
00008  * Copyright (c) 1993-2000 Equivalence Pty. Ltd.
00009  *
00010  * The contents of this file are subject to the Mozilla Public License
00011  * Version 1.0 (the "License"); you may not use this file except in
00012  * compliance with the License. You may obtain a copy of the License at
00013  * http://www.mozilla.org/MPL/
00014  *
00015  * Software distributed under the License is distributed on an "AS IS"
00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00017  * the License for the specific language governing rights and limitations
00018  * under the License.
00019  *
00020  * The Original Code is Portable Windows Library.
00021  *
00022  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
00023  *
00024  * Contributor(s): ______________________________________.
00025  *
00026  * $Log: random.h,v $
00027  * Revision 1.5  2004/11/11 07:34:50  csoutheren
00028  * Added #include <ptlib.h>
00029  *
00030  * Revision 1.4  2002/09/16 01:08:59  robertj
00031  * Added #define so can select if #pragma interface/implementation is used on
00032  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00033  *
00034  * Revision 1.3  2001/03/03 05:12:47  robertj
00035  * Fixed yet another transcription error of random number generator code.
00036  *
00037  * Revision 1.2  2001/02/27 03:33:44  robertj
00038  * Changed random number generator due to licensing issues.
00039  *
00040  * Revision 1.1  2000/02/17 12:05:02  robertj
00041  * Added better random number generator after finding major flaws in MSVCRT version.
00042  *
00043  */
00044 
00045 #ifndef _PRANDOM
00046 #define _PRANDOM
00047 
00048 
00049 #ifdef P_USE_PRAGMA
00050 #pragma interface
00051 #endif
00052 
00053 #include <ptlib.h>
00054 
00071 class PRandom
00072 {
00073   public:
00078     PRandom();
00079 
00084     PRandom(
00085       DWORD seed    
00086     );
00087 
00090     void SetSeed(
00091       DWORD seed    
00092     );
00093 
00098     unsigned Generate();
00099 
00102     inline operator unsigned() { return Generate(); }
00103 
00104 
00109     static unsigned Number();
00110 
00111 
00112   protected:
00113     enum {
00114       RandBits = 8, // I recommend 8 for crypto, 4 for simulations
00115       RandSize = 1<<RandBits
00116     };
00117 
00118     DWORD randcnt;
00119     DWORD randrsl[RandSize];
00120     DWORD randmem[RandSize];
00121     DWORD randa;
00122     DWORD randb;
00123     DWORD randc;
00124 };
00125 
00126 
00127 #endif  // _PRANDOM
00128 
00129 
00130 // End Of File ///////////////////////////////////////////////////////////////

Generated on Sat Dec 22 16:46:51 2007 for PWLib by  doxygen 1.4.2