00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef PTLIB_RANDOM_H
00032 #define PTLIB_RANDOM_H
00033
00034
00035 #ifdef P_USE_PRAGMA
00036 #pragma interface
00037 #endif
00038
00039
00056 class PRandom
00057 {
00058 public:
00063 PRandom();
00064
00069 PRandom(
00070 DWORD seed
00071 );
00072
00075 void SetSeed(
00076 DWORD seed
00077 );
00078
00083 unsigned Generate();
00084
00089 unsigned Generate(unsigned maximum);
00090
00095 unsigned Generate(unsigned minimum, unsigned maximum);
00096
00102 inline operator unsigned() { return Generate(); }
00103
00104
00109 static unsigned Number();
00110
00113 static unsigned Number(unsigned maximum);
00114
00117 static unsigned Number(unsigned minimum, unsigned maximum);
00118
00119 protected:
00120 enum {
00121 RandBits = 8,
00122 RandSize = 1<<RandBits
00123 };
00124
00125 DWORD randcnt;
00126 DWORD randrsl[RandSize];
00127 DWORD randmem[RandSize];
00128 DWORD randa;
00129 DWORD randb;
00130 DWORD randc;
00131 };
00132
00133
00134 #endif // PTLIB_RANDOM_H
00135
00136
00137