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