PTLib  Version 2.18.8
 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 
27 #ifndef PTLIB_RANDOM_H
28 #define PTLIB_RANDOM_H
29 
30 
31 #ifdef P_USE_PRAGMA
32 #pragma interface
33 #endif
34 
35 
52 class PRandom
53 {
54  public:
59  PRandom();
60 
65  PRandom(
66  uint32_t seed
67  );
68 
71  void SetSeed(
72  uint32_t seed
73  );
74 
79  uint32_t Generate();
80 
86  uint32_t Generate(uint32_t maximum);
87 
93  uint32_t Generate(uint32_t minimum, uint32_t maximum);
94 
100  inline operator uint32_t() { return Generate(); }
101 
102 
107  static uint32_t Number();
108 
111  static uint32_t Number(unsigned maximum);
112 
115  static uint32_t Number(unsigned minimum, unsigned maximum);
116 
119  static PBYTEArray Octets(PINDEX size);
120  static void Octets(PBYTEArray & octets, PINDEX size = 0);
121  static void Octets(BYTE * octets, PINDEX size);
122 
124  static PString String(PINDEX size);
125 
126  protected:
127  enum {
128  RandBits = 8,
130  };
131 
132  uint32_t randcnt;
133  uint32_t randrsl[RandSize];
134  uint32_t randmem[RandSize];
135  uint32_t randa;
136  uint32_t randb;
137  uint32_t randc;
138 };
139 
140 
141 #endif // PTLIB_RANDOM_H
142 
143 
144 // End Of File ///////////////////////////////////////////////////////////////
uint32_t randcnt
Definition: random.h:132
uint32_t randmem[RandSize]
Definition: random.h:134
PRandom()
Construct the random number generator.
static PString String(PINDEX size)
Get a string of random alphanumeric characters.
uint32_t randrsl[RandSize]
Definition: random.h:133
static PBYTEArray Octets(PINDEX size)
Get a random set of bits.
void SetSeed(uint32_t seed)
Set the seed for the random number generator.
Array of unsigned characters.
Definition: array.h:605
static uint32_t Number()
Get the next psuedo-random number in sequence.
uint32_t randb
Definition: random.h:136
uint32_t Generate()
Get the next psuedo-random number in sequence.
The character string class.
Definition: pstring.h:108
Definition: random.h:129
uint32_t randa
Definition: random.h:135
I recommend 8 for crypto, 4 for simulations.
Definition: random.h:128
Mersenne Twister random number generator.
Definition: random.h:52
uint32_t randc
Definition: random.h:137