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