1 | /* |
---|
2 | * Licensed under the GNU Lesser General Public License Version 3 |
---|
3 | * |
---|
4 | * This library is free software: you can redistribute it and/or modify |
---|
5 | * it under the terms of the GNU Lesser General Public License as published by |
---|
6 | * the Free Software Foundation, either version 3 of the license, or |
---|
7 | * (at your option) any later version. |
---|
8 | * |
---|
9 | * This software is distributed in the hope that it will be useful, |
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | * GNU Lesser General Public License for more details. |
---|
13 | * |
---|
14 | * You should have received a copy of the GNU Lesser General Public License |
---|
15 | * along with this library. If not, see <http://www.gnu.org/licenses/>. |
---|
16 | */ |
---|
17 | |
---|
18 | // generated automatically - do not change |
---|
19 | |
---|
20 | |
---|
21 | module glib.RandG; |
---|
22 | |
---|
23 | private import gi.glib; |
---|
24 | public import gi.glibtypes; |
---|
25 | private import glib.ConstructionException; |
---|
26 | |
---|
27 | |
---|
28 | /** |
---|
29 | * The GRand struct is an opaque data structure. It should only be |
---|
30 | * accessed through the g_rand_* functions. |
---|
31 | */ |
---|
32 | public class RandG |
---|
33 | { |
---|
34 | /** the main Gtk struct */ |
---|
35 | protected GRand* gRand; |
---|
36 | protected bool ownedRef; |
---|
37 | |
---|
38 | /** Get the main Gtk struct */ |
---|
39 | public GRand* getRandGStruct() |
---|
40 | { |
---|
41 | return gRand; |
---|
42 | } |
---|
43 | |
---|
44 | /** the main Gtk struct as a void* */ |
---|
45 | protected void* getStruct() |
---|
46 | { |
---|
47 | return cast(void*)gRand; |
---|
48 | } |
---|
49 | |
---|
50 | /** |
---|
51 | * Sets our main struct and passes it to the parent class. |
---|
52 | */ |
---|
53 | public this (GRand* gRand, bool ownedRef = false) |
---|
54 | { |
---|
55 | this.gRand = gRand; |
---|
56 | this.ownedRef = ownedRef; |
---|
57 | } |
---|
58 | |
---|
59 | |
---|
60 | /** |
---|
61 | * Copies a #GRand into a new one with the same exact state as before. |
---|
62 | * This way you can take a snapshot of the random number generator for |
---|
63 | * replaying later. |
---|
64 | * |
---|
65 | * Returns: the new #GRand |
---|
66 | * |
---|
67 | * Since: 2.4 |
---|
68 | */ |
---|
69 | public RandG copy() |
---|
70 | { |
---|
71 | auto p = g_rand_copy(gRand); |
---|
72 | |
---|
73 | if(p is null) |
---|
74 | { |
---|
75 | return null; |
---|
76 | } |
---|
77 | |
---|
78 | return new RandG(cast(GRand*) p); |
---|
79 | } |
---|
80 | |
---|
81 | /** |
---|
82 | * Returns the next random #gdouble from @rand_ equally distributed over |
---|
83 | * the range [0..1). |
---|
84 | * |
---|
85 | * Returns: a random number |
---|
86 | */ |
---|
87 | public double randDouble() |
---|
88 | { |
---|
89 | return g_rand_double(gRand); |
---|
90 | } |
---|
91 | |
---|
92 | /** |
---|
93 | * Returns the next random #gdouble from @rand_ equally distributed over |
---|
94 | * the range [@begin..@end). |
---|
95 | * |
---|
96 | * Params: |
---|
97 | * begin = lower closed bound of the interval |
---|
98 | * end = upper open bound of the interval |
---|
99 | * |
---|
100 | * Returns: a random number |
---|
101 | */ |
---|
102 | public double doubleRange(double begin, double end) |
---|
103 | { |
---|
104 | return g_rand_double_range(gRand, begin, end); |
---|
105 | } |
---|
106 | |
---|
107 | /** |
---|
108 | * Frees the memory allocated for the #GRand. |
---|
109 | */ |
---|
110 | public void free() |
---|
111 | { |
---|
112 | g_rand_free(gRand); |
---|
113 | } |
---|
114 | |
---|
115 | /** |
---|
116 | * Returns the next random #guint32 from @rand_ equally distributed over |
---|
117 | * the range [0..2^32-1]. |
---|
118 | * |
---|
119 | * Returns: a random number |
---|
120 | */ |
---|
121 | public uint randInt() |
---|
122 | { |
---|
123 | return g_rand_int(gRand); |
---|
124 | } |
---|
125 | |
---|
126 | /** |
---|
127 | * Returns the next random #gint32 from @rand_ equally distributed over |
---|
128 | * the range [@begin..@end-1]. |
---|
129 | * |
---|
130 | * Params: |
---|
131 | * begin = lower closed bound of the interval |
---|
132 | * end = upper open bound of the interval |
---|
133 | * |
---|
134 | * Returns: a random number |
---|
135 | */ |
---|
136 | public int intRange(int begin, int end) |
---|
137 | { |
---|
138 | return g_rand_int_range(gRand, begin, end); |
---|
139 | } |
---|
140 | |
---|
141 | /** |
---|
142 | * Sets the seed for the random number generator #GRand to @seed. |
---|
143 | * |
---|
144 | * Params: |
---|
145 | * seed = a value to reinitialize the random number generator |
---|
146 | */ |
---|
147 | public void setSeed(uint seed) |
---|
148 | { |
---|
149 | g_rand_set_seed(gRand, seed); |
---|
150 | } |
---|
151 | |
---|
152 | /** |
---|
153 | * Initializes the random number generator by an array of longs. |
---|
154 | * Array can be of arbitrary size, though only the first 624 values |
---|
155 | * are taken. This function is useful if you have many low entropy |
---|
156 | * seeds, or if you require more then 32 bits of actual entropy for |
---|
157 | * your application. |
---|
158 | * |
---|
159 | * Params: |
---|
160 | * seed = array to initialize with |
---|
161 | * seedLength = length of array |
---|
162 | * |
---|
163 | * Since: 2.4 |
---|
164 | */ |
---|
165 | public void setSeedArray(uint* seed, uint seedLength) |
---|
166 | { |
---|
167 | g_rand_set_seed_array(gRand, seed, seedLength); |
---|
168 | } |
---|
169 | |
---|
170 | /** |
---|
171 | * Creates a new random number generator initialized with a seed taken |
---|
172 | * either from `/dev/urandom` (if existing) or from the current time |
---|
173 | * (as a fallback). |
---|
174 | * |
---|
175 | * On Windows, the seed is taken from rand_s(). |
---|
176 | * |
---|
177 | * Returns: the new #GRand |
---|
178 | * |
---|
179 | * Throws: ConstructionException GTK+ fails to create the object. |
---|
180 | */ |
---|
181 | public this() |
---|
182 | { |
---|
183 | auto p = g_rand_new(); |
---|
184 | |
---|
185 | if(p is null) |
---|
186 | { |
---|
187 | throw new ConstructionException("null returned by new"); |
---|
188 | } |
---|
189 | |
---|
190 | this(cast(GRand*) p); |
---|
191 | } |
---|
192 | |
---|
193 | /** |
---|
194 | * Creates a new random number generator initialized with @seed. |
---|
195 | * |
---|
196 | * Params: |
---|
197 | * seed = a value to initialize the random number generator |
---|
198 | * |
---|
199 | * Returns: the new #GRand |
---|
200 | * |
---|
201 | * Throws: ConstructionException GTK+ fails to create the object. |
---|
202 | */ |
---|
203 | public this(uint seed) |
---|
204 | { |
---|
205 | auto p = g_rand_new_with_seed(seed); |
---|
206 | |
---|
207 | if(p is null) |
---|
208 | { |
---|
209 | throw new ConstructionException("null returned by new_with_seed"); |
---|
210 | } |
---|
211 | |
---|
212 | this(cast(GRand*) p); |
---|
213 | } |
---|
214 | |
---|
215 | /** |
---|
216 | * Creates a new random number generator initialized with @seed. |
---|
217 | * |
---|
218 | * Params: |
---|
219 | * seed = an array of seeds to initialize the random number generator |
---|
220 | * seedLength = an array of seeds to initialize the random number |
---|
221 | * generator |
---|
222 | * |
---|
223 | * Returns: the new #GRand |
---|
224 | * |
---|
225 | * Since: 2.4 |
---|
226 | * |
---|
227 | * Throws: ConstructionException GTK+ fails to create the object. |
---|
228 | */ |
---|
229 | public this(uint[] seed) |
---|
230 | { |
---|
231 | auto p = g_rand_new_with_seed_array(seed.ptr, cast(uint)seed.length); |
---|
232 | |
---|
233 | if(p is null) |
---|
234 | { |
---|
235 | throw new ConstructionException("null returned by new_with_seed_array"); |
---|
236 | } |
---|
237 | |
---|
238 | this(cast(GRand*) p); |
---|
239 | } |
---|
240 | |
---|
241 | /** |
---|
242 | * Returns a random #gdouble equally distributed over the range [0..1). |
---|
243 | * |
---|
244 | * Returns: a random number |
---|
245 | */ |
---|
246 | public static double randomDouble() |
---|
247 | { |
---|
248 | return g_random_double(); |
---|
249 | } |
---|
250 | |
---|
251 | /** |
---|
252 | * Returns a random #gdouble equally distributed over the range |
---|
253 | * [@begin..@end). |
---|
254 | * |
---|
255 | * Params: |
---|
256 | * begin = lower closed bound of the interval |
---|
257 | * end = upper open bound of the interval |
---|
258 | * |
---|
259 | * Returns: a random number |
---|
260 | */ |
---|
261 | public static double randomDoubleRange(double begin, double end) |
---|
262 | { |
---|
263 | return g_random_double_range(begin, end); |
---|
264 | } |
---|
265 | |
---|
266 | /** |
---|
267 | * Return a random #guint32 equally distributed over the range |
---|
268 | * [0..2^32-1]. |
---|
269 | * |
---|
270 | * Returns: a random number |
---|
271 | */ |
---|
272 | public static uint randomInt() |
---|
273 | { |
---|
274 | return g_random_int(); |
---|
275 | } |
---|
276 | |
---|
277 | /** |
---|
278 | * Returns a random #gint32 equally distributed over the range |
---|
279 | * [@begin..@end-1]. |
---|
280 | * |
---|
281 | * Params: |
---|
282 | * begin = lower closed bound of the interval |
---|
283 | * end = upper open bound of the interval |
---|
284 | * |
---|
285 | * Returns: a random number |
---|
286 | */ |
---|
287 | public static int randomIntRange(int begin, int end) |
---|
288 | { |
---|
289 | return g_random_int_range(begin, end); |
---|
290 | } |
---|
291 | |
---|
292 | /** |
---|
293 | * Sets the seed for the global random number generator, which is used |
---|
294 | * by the g_random_* functions, to @seed. |
---|
295 | * |
---|
296 | * Params: |
---|
297 | * seed = a value to reinitialize the global random number generator |
---|
298 | */ |
---|
299 | public static void randomSetSeed(uint seed) |
---|
300 | { |
---|
301 | g_random_set_seed(seed); |
---|
302 | } |
---|
303 | } |
---|