PTLib  Version 2.14.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
random.h
Go to the documentation of this file.
1 /*
2  * random.h
3  *
4  * ISAAC random number generator by Bob Jenkins.
5  *
6  * Portable Windows Library
7  *
8  * Copyright (c) 1993-2000 Equivalence Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Windows Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Contributor(s): ______________________________________.
25  *
26  * $Revision: 31215 $
27  * $Author: rjongbloed $
28  * $Date: 2014-01-17 21:12:50 +1100 (Fri, 17 Jan 2014) $
29  */
30 
31 #ifndef PTLIB_RANDOM_H
32 #define PTLIB_RANDOM_H
33 
34 
35 #ifdef P_USE_PRAGMA
36 #pragma interface
37 #endif
38 
39 
56 class PRandom
57 {
58  public:
63  PRandom();
64 
69  PRandom(
70  uint32_t seed
71  );
72 
75  void SetSeed(
76  uint32_t seed
77  );
78 
83  uint32_t Generate();
84 
89  uint32_t Generate(uint32_t maximum);
90 
95  uint32_t Generate(uint32_t minimum, uint32_t maximum);
96 
102  inline operator uint32_t() { return Generate(); }
103 
104 
109  static uint32_t Number();
110 
113  static uint32_t Number(unsigned maximum);
114 
117  static uint32_t Number(unsigned minimum, unsigned maximum);
118 
121  static PBYTEArray Octets(PINDEX size);
122  static void Octets(PBYTEArray & octets, PINDEX size = 0);
123  static void Octets(BYTE * octets, PINDEX size);
124 
125  protected:
126  enum {
127  RandBits = 8,
129  };
130 
131  uint32_t randcnt;
132  uint32_t randrsl[RandSize];
133  uint32_t randmem[RandSize];
134  uint32_t randa;
135  uint32_t randb;
136  uint32_t randc;
137 };
138 
139 
140 #endif // PTLIB_RANDOM_H
141 
142 
143 // End Of File ///////////////////////////////////////////////////////////////