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.6 2005/11/30 12:47:37 csoutheren 00028 * Removed tabs, reformatted some code, and changed tags for Doxygen 00029 * 00030 * Revision 1.5 2004/11/11 07:34:50 csoutheren 00031 * Added #include <ptlib.h> 00032 * 00033 * Revision 1.4 2002/09/16 01:08:59 robertj 00034 * Added #define so can select if #pragma interface/implementation is used on 00035 * platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan. 00036 * 00037 * Revision 1.3 2001/03/03 05:12:47 robertj 00038 * Fixed yet another transcription error of random number generator code. 00039 * 00040 * Revision 1.2 2001/02/27 03:33:44 robertj 00041 * Changed random number generator due to licensing issues. 00042 * 00043 * Revision 1.1 2000/02/17 12:05:02 robertj 00044 * Added better random number generator after finding major flaws in MSVCRT version. 00045 * 00046 */ 00047 00048 #ifndef _PRANDOM 00049 #define _PRANDOM 00050 00051 00052 #ifdef P_USE_PRAGMA 00053 #pragma interface 00054 #endif 00055 00056 #include <ptlib.h> 00057 00074 class PRandom 00075 { 00076 public: 00081 PRandom(); 00082 00087 PRandom( 00088 DWORD seed 00089 ); 00090 00093 void SetSeed( 00094 DWORD seed 00095 ); 00096 00101 unsigned Generate(); 00102 00105 inline operator unsigned() { return Generate(); } 00106 00107 00112 static unsigned Number(); 00113 00114 00115 protected: 00116 enum { 00117 RandBits = 8, 00118 RandSize = 1<<RandBits 00119 }; 00120 00121 DWORD randcnt; 00122 DWORD randrsl[RandSize]; 00123 DWORD randmem[RandSize]; 00124 DWORD randa; 00125 DWORD randb; 00126 DWORD randc; 00127 }; 00128 00129 00130 #endif // _PRANDOM 00131 00132 00133 // End Of File ///////////////////////////////////////////////////////////////