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.4 2002/09/16 01:08:59 robertj 00028 * Added #define so can select if #pragma interface/implementation is used on 00029 * platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan. 00030 * 00031 * Revision 1.3 2001/03/03 05:12:47 robertj 00032 * Fixed yet another transcription error of random number generator code. 00033 * 00034 * Revision 1.2 2001/02/27 03:33:44 robertj 00035 * Changed random number generator due to licensing issues. 00036 * 00037 * Revision 1.1 2000/02/17 12:05:02 robertj 00038 * Added better random number generator after finding major flaws in MSVCRT version. 00039 * 00040 */ 00041 00042 #ifndef _PRANDOM 00043 #define _PRANDOM 00044 00045 00046 #ifdef P_USE_PRAGMA 00047 #pragma interface 00048 #endif 00049 00050 00051 00068 class PRandom 00069 { 00070 public: 00075 PRandom(); 00076 00081 PRandom( 00082 DWORD seed 00083 ); 00084 00087 void SetSeed( 00088 DWORD seed 00089 ); 00090 00095 unsigned Generate(); 00096 00099 inline operator unsigned() { return Generate(); } 00100 00101 00106 static unsigned Number(); 00107 00108 00109 protected: 00110 enum { 00111 RandBits = 8, // I recommend 8 for crypto, 4 for simulations 00112 RandSize = 1<<RandBits 00113 }; 00114 00115 DWORD randcnt; 00116 DWORD randrsl[RandSize]; 00117 DWORD randmem[RandSize]; 00118 DWORD randa; 00119 DWORD randb; 00120 DWORD randc; 00121 }; 00122 00123 00124 #endif // _PRANDOM 00125 00126 00127 // End Of File ///////////////////////////////////////////////////////////////