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.8 2007/04/18 23:49:50 csoutheren 00028 * Add usage of precompiled headers 00029 * 00030 * Revision 1.7 2007/03/08 04:31:08 csoutheren 00031 * Applied 1613299 - add new function to the PRandom class 00032 * Thanks to Frederic Heem 00033 * 00034 * Revision 1.6 2005/11/30 12:47:37 csoutheren 00035 * Removed tabs, reformatted some code, and changed tags for Doxygen 00036 * 00037 * Revision 1.5 2004/11/11 07:34:50 csoutheren 00038 * Added #include <ptlib.h> 00039 * 00040 * Revision 1.4 2002/09/16 01:08:59 robertj 00041 * Added #define so can select if #pragma interface/implementation is used on 00042 * platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan. 00043 * 00044 * Revision 1.3 2001/03/03 05:12:47 robertj 00045 * Fixed yet another transcription error of random number generator code. 00046 * 00047 * Revision 1.2 2001/02/27 03:33:44 robertj 00048 * Changed random number generator due to licensing issues. 00049 * 00050 * Revision 1.1 2000/02/17 12:05:02 robertj 00051 * Added better random number generator after finding major flaws in MSVCRT version. 00052 * 00053 */ 00054 00055 #ifndef _PRANDOM 00056 #define _PRANDOM 00057 00058 00059 #ifdef P_USE_PRAGMA 00060 #pragma interface 00061 #endif 00062 00063 #ifndef _PTLIB_H 00064 #include <ptlib.h> 00065 #endif 00066 00083 class PRandom 00084 { 00085 public: 00090 PRandom(); 00091 00096 PRandom( 00097 DWORD seed 00098 ); 00099 00102 void SetSeed( 00103 DWORD seed 00104 ); 00105 00110 unsigned Generate(); 00111 00114 inline operator unsigned() { return Generate(); } 00115 00116 00121 static unsigned Number(); 00122 00125 static unsigned int Number(unsigned int min, unsigned int max); 00126 00127 protected: 00128 enum { 00129 RandBits = 8, 00130 RandSize = 1<<RandBits 00131 }; 00132 00133 DWORD randcnt; 00134 DWORD randrsl[RandSize]; 00135 DWORD randmem[RandSize]; 00136 DWORD randa; 00137 DWORD randb; 00138 DWORD randc; 00139 }; 00140 00141 00142 #endif // _PRANDOM 00143 00144 00145 // End Of File ///////////////////////////////////////////////////////////////