1 | /** @file
|
---|
2 | * IPRT - Random Numbers and Byte Streams.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | *
|
---|
25 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
26 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
27 | * additional information or have any questions.
|
---|
28 | */
|
---|
29 |
|
---|
30 | #ifndef ___iprt_rand_h
|
---|
31 | #define ___iprt_rand_h
|
---|
32 |
|
---|
33 | #include <iprt/cdefs.h>
|
---|
34 | #include <iprt/types.h>
|
---|
35 |
|
---|
36 | __BEGIN_DECLS
|
---|
37 |
|
---|
38 | /** @defgroup grp_rt_rand RTRand - Random Numbers and Byte Streams
|
---|
39 | * @ingroup grp_rt
|
---|
40 | * @{
|
---|
41 | */
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * Fills a buffer with random bytes.
|
---|
45 | *
|
---|
46 | * @param pv Where to store the random bytes.
|
---|
47 | * @param cb Number of bytes to generate.
|
---|
48 | */
|
---|
49 | RTDECL(void) RTRandBytes(void *pv, size_t cb) RT_NO_THROW;
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * Generate a 32-bit signed random number in the set [i32First..i32Last].
|
---|
53 | *
|
---|
54 | * @returns The random number.
|
---|
55 | * @param i32First First number in the set.
|
---|
56 | * @param i32Last Last number in the set.
|
---|
57 | */
|
---|
58 | RTDECL(int32_t) RTRandS32Ex(int32_t i32First, int32_t i32Last) RT_NO_THROW;
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * Generate a 32-bit signed random number.
|
---|
62 | *
|
---|
63 | * @returns The random number.
|
---|
64 | */
|
---|
65 | RTDECL(int32_t) RTRandS32(void) RT_NO_THROW;
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Generate a 32-bit unsigned random number in the set [u32First..u32Last].
|
---|
69 | *
|
---|
70 | * @returns The random number.
|
---|
71 | * @param u32First First number in the set.
|
---|
72 | * @param u32Last Last number in the set.
|
---|
73 | */
|
---|
74 | RTDECL(uint32_t) RTRandU32Ex(uint32_t u32First, uint32_t u32Last) RT_NO_THROW;
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * Generate a 32-bit unsigned random number.
|
---|
78 | *
|
---|
79 | * @returns The random number.
|
---|
80 | */
|
---|
81 | RTDECL(uint32_t) RTRandU32(void) RT_NO_THROW;
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * Generate a 64-bit signed random number in the set [i64First..i64Last].
|
---|
85 | *
|
---|
86 | * @returns The random number.
|
---|
87 | * @param i64First First number in the set.
|
---|
88 | * @param i64Last Last number in the set.
|
---|
89 | */
|
---|
90 | RTDECL(int64_t) RTRandS64Ex(int64_t i64First, int64_t i64Last) RT_NO_THROW;
|
---|
91 |
|
---|
92 | /**
|
---|
93 | * Generate a 64-bit signed random number.
|
---|
94 | *
|
---|
95 | * @returns The random number.
|
---|
96 | */
|
---|
97 | RTDECL(int64_t) RTRandS64(void) RT_NO_THROW;
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * Generate a 64-bit unsigned random number in the set [u64First..u64Last].
|
---|
101 | *
|
---|
102 | * @returns The random number.
|
---|
103 | * @param u64First First number in the set.
|
---|
104 | * @param u64Last Last number in the set.
|
---|
105 | */
|
---|
106 | RTDECL(uint64_t) RTRandU64Ex(uint64_t u64First, uint64_t u64Last) RT_NO_THROW;
|
---|
107 |
|
---|
108 | /**
|
---|
109 | * Generate a 64-bit unsigned random number.
|
---|
110 | *
|
---|
111 | * @returns The random number.
|
---|
112 | */
|
---|
113 | RTDECL(uint64_t) RTRandU64(void) RT_NO_THROW;
|
---|
114 |
|
---|
115 |
|
---|
116 | /**
|
---|
117 | * Create an instance of the default random number generator.
|
---|
118 | *
|
---|
119 | * @returns IPRT status code.
|
---|
120 | * @param hRand Handle to the random number generator.
|
---|
121 | */
|
---|
122 | RTDECL(int) RTRandAdvCreate(PRTRAND phRand) RT_NO_THROW;
|
---|
123 |
|
---|
124 | /**
|
---|
125 | * Create an instance of the default pseudo random number generator.
|
---|
126 | *
|
---|
127 | * @returns IPRT status code.
|
---|
128 | * @param phRand Where to store the handle to the generator.
|
---|
129 | */
|
---|
130 | RTDECL(int) RTRandAdvCreatePseudo(PRTRAND phRand) RT_NO_THROW;
|
---|
131 |
|
---|
132 |
|
---|
133 | /**
|
---|
134 | * Create an instance of the Park-Miller pseudo random number generator.
|
---|
135 | *
|
---|
136 | * @returns IPRT status code.
|
---|
137 | * @param phRand Where to store the handle to the generator.
|
---|
138 | */
|
---|
139 | RTDECL(int) RTRandAdvCreateParkMiller(PRTRAND phRand) RT_NO_THROW;
|
---|
140 |
|
---|
141 | /**
|
---|
142 | * Destroys a random number generator.
|
---|
143 | *
|
---|
144 | * @returns IPRT status code.
|
---|
145 | * @param hRand Handle to the random number generator.
|
---|
146 | */
|
---|
147 | RTDECL(int) RTRandAdvDestroy(RTRAND hRand) RT_NO_THROW;
|
---|
148 |
|
---|
149 | /**
|
---|
150 | * Generic method for seeding of a random number generator.
|
---|
151 | *
|
---|
152 | * The different generators may have specialized methods for
|
---|
153 | * seeding, use one of those if you desire better control
|
---|
154 | * over ther result.
|
---|
155 | *
|
---|
156 | * @returns IPRT status code.
|
---|
157 | * @param hRand Handle to the random number generator.
|
---|
158 | * @param u64Seed Seed.
|
---|
159 | */
|
---|
160 | RTDECL(int) RTRandAdvSeed(RTRAND hRand, uint64_t u64Seed) RT_NO_THROW;
|
---|
161 |
|
---|
162 | /**
|
---|
163 | * Fills a buffer with random bytes.
|
---|
164 | *
|
---|
165 | * @param hRand Handle to the random number generator.
|
---|
166 | * @param pv Where to store the random bytes.
|
---|
167 | * @param cb Number of bytes to generate.
|
---|
168 | */
|
---|
169 | RTDECL(void) RTRandAdvBytes(RTRAND hRand, void *pv, size_t cb) RT_NO_THROW;
|
---|
170 |
|
---|
171 | /**
|
---|
172 | * Generate a 32-bit signed random number in the set [i32First..i32Last].
|
---|
173 | *
|
---|
174 | * @returns The random number.
|
---|
175 | * @param hRand Handle to the random number generator.
|
---|
176 | * @param i32First First number in the set.
|
---|
177 | * @param i32Last Last number in the set.
|
---|
178 | */
|
---|
179 | RTDECL(int32_t) RTRandAdvS32Ex(RTRAND hRand, int32_t i32First, int32_t i32Last) RT_NO_THROW;
|
---|
180 |
|
---|
181 | /**
|
---|
182 | * Generate a 32-bit signed random number.
|
---|
183 | *
|
---|
184 | * @returns The random number.
|
---|
185 | * @param hRand Handle to the random number generator.
|
---|
186 | */
|
---|
187 | RTDECL(int32_t) RTRandAdvS32(RTRAND hRand) RT_NO_THROW;
|
---|
188 |
|
---|
189 | /**
|
---|
190 | * Generate a 32-bit unsigned random number in the set [u32First..u32Last].
|
---|
191 | *
|
---|
192 | * @returns The random number.
|
---|
193 | * @param hRand Handle to the random number generator.
|
---|
194 | * @param u32First First number in the set.
|
---|
195 | * @param u32Last Last number in the set.
|
---|
196 | */
|
---|
197 | RTDECL(uint32_t) RTRandAdvU32Ex(RTRAND hRand, uint32_t u32First, uint32_t u32Last) RT_NO_THROW;
|
---|
198 |
|
---|
199 | /**
|
---|
200 | * Generate a 32-bit unsigned random number.
|
---|
201 | *
|
---|
202 | * @returns The random number.
|
---|
203 | * @param hRand Handle to the random number generator.
|
---|
204 | */
|
---|
205 | RTDECL(uint32_t) RTRandAdvU32(RTRAND hRand) RT_NO_THROW;
|
---|
206 |
|
---|
207 | /**
|
---|
208 | * Generate a 64-bit signed random number in the set [i64First..i64Last].
|
---|
209 | *
|
---|
210 | * @returns The random number.
|
---|
211 | * @param hRand Handle to the random number generator.
|
---|
212 | * @param i64First First number in the set.
|
---|
213 | * @param i64Last Last number in the set.
|
---|
214 | */
|
---|
215 | RTDECL(int64_t) RTRandAdvS64Ex(RTRAND hRand, int64_t i64First, int64_t i64Last) RT_NO_THROW;
|
---|
216 |
|
---|
217 | /**
|
---|
218 | * Generate a 64-bit signed random number.
|
---|
219 | *
|
---|
220 | * @returns The random number.
|
---|
221 | */
|
---|
222 | RTDECL(int64_t) RTRandAdvS64(RTRAND hRand) RT_NO_THROW;
|
---|
223 |
|
---|
224 | /**
|
---|
225 | * Generate a 64-bit unsigned random number in the set [u64First..u64Last].
|
---|
226 | *
|
---|
227 | * @returns The random number.
|
---|
228 | * @param hRand Handle to the random number generator.
|
---|
229 | * @param u64First First number in the set.
|
---|
230 | * @param u64Last Last number in the set.
|
---|
231 | */
|
---|
232 | RTDECL(uint64_t) RTRandAdvU64Ex(RTRAND hRand, uint64_t u64First, uint64_t u64Last) RT_NO_THROW;
|
---|
233 |
|
---|
234 | /**
|
---|
235 | * Generate a 64-bit unsigned random number.
|
---|
236 | *
|
---|
237 | * @returns The random number.
|
---|
238 | * @param hRand Handle to the random number generator.
|
---|
239 | */
|
---|
240 | RTDECL(uint64_t) RTRandAdvU64(RTRAND hRand) RT_NO_THROW;
|
---|
241 |
|
---|
242 |
|
---|
243 | /** @} */
|
---|
244 |
|
---|
245 | __END_DECLS
|
---|
246 |
|
---|
247 |
|
---|
248 | #endif
|
---|
249 |
|
---|