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  * $Revision: 20385 $
00027  * $Author: rjongbloed $
00028  * $Date: 2008-06-04 10:40:38 +0000 (Wed, 04 Jun 2008) $
00029  */
00030 
00031 #ifndef _PRANDOM
00032 #define _PRANDOM
00033 
00034 
00035 #ifdef P_USE_PRAGMA
00036 #pragma interface
00037 #endif
00038 
00039 #ifndef _PTLIB_H
00040 #include <ptlib.h>
00041 #endif
00042 
00059 class PRandom
00060 {
00061   public:
00066     PRandom();
00067 
00072     PRandom(
00073       DWORD seed    
00074     );
00075 
00078     void SetSeed(
00079       DWORD seed    
00080     );
00081 
00086     unsigned Generate();
00087 
00092     unsigned Generate(unsigned maximum);
00093 
00098     unsigned Generate(unsigned minimum, unsigned maximum);
00099 
00105     inline operator unsigned() { return Generate(); }
00106 
00107 
00112     static unsigned Number();
00113 
00116     static unsigned Number(unsigned maximum);
00117 
00120     static unsigned Number(unsigned minimum, unsigned maximum);
00121 
00122   protected:
00123     enum {
00124       RandBits = 8, 
00125       RandSize = 1<<RandBits
00126     };
00127 
00128     DWORD randcnt;
00129     DWORD randrsl[RandSize];
00130     DWORD randmem[RandSize];
00131     DWORD randa;
00132     DWORD randb;
00133     DWORD randc;
00134 };
00135 
00136 
00137 #endif  // _PRANDOM
00138 
00139 
00140 // End Of File ///////////////////////////////////////////////////////////////

Generated on Mon Sep 15 01:21:35 2008 for PTLib by  doxygen 1.5.1