/src/wrappers/glib/library/utilities/glib_random_numbers.e

http://github.com/tybor/Liberty · Specman e · 306 lines · 2 code · 109 blank · 195 comment · 0 complexity · dd520fbe6721c6adfdaa75826a272f8c MD5 · raw file

  1. deferred class GLIB_RANDOM_NUMBERS
  2. -- Random Numbers
  3. -- Random Numbers -- pseudo-random number generator.
  4. -- Synopsis
  5. -- #include <glib.h>
  6. -- GRand;
  7. -- GRand* g_rand_new_with_seed (guint32 seed);
  8. -- GRand* g_rand_new_with_seed_array (const guint32 *seed,
  9. -- guint seed_length);
  10. -- GRand* g_rand_new (void);
  11. -- GRand* g_rand_copy (GRand *rand_);
  12. -- void g_rand_free (GRand *rand_);
  13. -- void g_rand_set_seed (GRand *rand_,
  14. -- guint32 seed);
  15. -- void g_rand_set_seed_array (GRand *rand_,
  16. -- const guint32 *seed,
  17. -- guint seed_length);
  18. -- #define g_rand_boolean (rand_)
  19. -- guint32 g_rand_int (GRand *rand_);
  20. -- gint32 g_rand_int_range (GRand *rand_,
  21. -- gint32 begin,
  22. -- gint32 end);
  23. -- gdouble g_rand_double (GRand *rand_);
  24. -- gdouble g_rand_double_range (GRand *rand_,
  25. -- gdouble begin,
  26. -- gdouble end);
  27. -- void g_random_set_seed (guint32 seed);
  28. -- #define g_random_boolean ()
  29. -- guint32 g_random_int (void);
  30. -- gint32 g_random_int_range (gint32 begin,
  31. -- gint32 end);
  32. -- gdouble g_random_double (void);
  33. -- gdouble g_random_double_range (gdouble begin,
  34. -- gdouble end);
  35. -- Description
  36. -- The following functions allow you to use a portable, fast and good pseudo-random
  37. -- number generator (PRNG). It uses the Mersenne Twister PRNG, which was originally
  38. -- developed by Makoto Matsumoto and Takuji Nishimura. Further information can be
  39. -- found at www.math.keio.ac.jp/~matumoto/emt.html.
  40. -- If you just need a random number, you simply call the g_random_* functions, which
  41. -- will create a globally used GRand and use the according g_rand_* functions
  42. -- internally. Whenever you need a stream of reproducible random numbers, you better
  43. -- create a GRand yourself and use the g_rand_* functions directly, which will also
  44. -- be slightly faster. Initializing a GRand with a certain seed will produce exactly
  45. -- the same series of random numbers on all platforms. This can thus be used as a
  46. -- seed for e.g. games.
  47. -- The g_rand*_range functions will return high quality equally distributed random
  48. -- numbers, whereas for example the (g_random_int()%max) approach often doesn't
  49. -- yield equally distributed numbers.
  50. -- GLib changed the seeding algorithm for the pseudo-random number generator
  51. -- Mersenne Twister, as used by GRand and GRandom. This was necessary, because some
  52. -- seeds would yield very bad pseudo-random streams. Also the pseudo-random integers
  53. -- generated by g_rand*_int_range() will have a slightly better equal distribution
  54. -- with the new version of GLib.
  55. -- The original seeding and generation algorithms, as found in GLib 2.0.x, can be
  56. -- used instead of the new ones by setting the environment variable G_RANDOM_VERSION
  57. -- to the value of '2.0'. Use the GLib-2.0 algorithms only if you have sequences of
  58. -- numbers generated with Glib-2.0 that you need to reproduce exactly.
  59. -- Details
  60. -- GRand
  61. -- typedef struct _GRand GRand;
  62. -- The GRand struct is an opaque data structure. It should only be accessed through
  63. -- the g_rand_* functions.
  64. -- ---------------------------------------------------------------------------------
  65. -- g_rand_new_with_seed ()
  66. -- GRand* g_rand_new_with_seed (guint32 seed);
  67. -- Creates a new random number generator initialized with seed.
  68. -- seed : a value to initialize the random number generator.
  69. -- Returns : the new GRand.
  70. -- ---------------------------------------------------------------------------------
  71. -- g_rand_new_with_seed_array ()
  72. -- GRand* g_rand_new_with_seed_array (const guint32 *seed,
  73. -- guint seed_length);
  74. -- Creates a new random number generator initialized with seed.
  75. -- seed : an array of seeds to initialize the random number generator.
  76. -- seed_length : an array of seeds to initialize the random number generator.
  77. -- Returns : the new GRand.
  78. -- Since 2.4
  79. -- ---------------------------------------------------------------------------------
  80. -- g_rand_new ()
  81. -- GRand* g_rand_new (void);
  82. -- Creates a new random number generator initialized with a seed taken either from
  83. -- /dev/urandom (if existing) or from the current time (as a fallback).
  84. -- Returns : the new GRand.
  85. -- ---------------------------------------------------------------------------------
  86. -- g_rand_copy ()
  87. -- GRand* g_rand_copy (GRand *rand_);
  88. -- Copies a GRand into a new one with the same exact state as before. This way you
  89. -- can take a snapshot of the random number generator for replaying later.
  90. -- rand_ : a GRand.
  91. -- Returns : the new GRand.
  92. -- Since 2.4
  93. -- ---------------------------------------------------------------------------------
  94. -- g_rand_free ()
  95. -- void g_rand_free (GRand *rand_);
  96. -- Frees the memory allocated for the GRand.
  97. -- rand_ : a GRand.
  98. -- ---------------------------------------------------------------------------------
  99. -- g_rand_set_seed ()
  100. -- void g_rand_set_seed (GRand *rand_,
  101. -- guint32 seed);
  102. -- Sets the seed for the random number generator GRand to seed.
  103. -- rand_ : a GRand.
  104. -- seed : a value to reinitialize the random number generator.
  105. -- ---------------------------------------------------------------------------------
  106. -- g_rand_set_seed_array ()
  107. -- void g_rand_set_seed_array (GRand *rand_,
  108. -- const guint32 *seed,
  109. -- guint seed_length);
  110. -- Initializes the random number generator by an array of longs. Array can be of
  111. -- arbitrary size, though only the first 624 values are taken. This function is
  112. -- useful if you have many low entropy seeds, or if you require more then 32bits of
  113. -- actual entropy for your application.
  114. -- rand_ : a GRand.
  115. -- seed : array to initialize with
  116. -- seed_length : length of array
  117. -- Since 2.4
  118. -- ---------------------------------------------------------------------------------
  119. -- g_rand_boolean()
  120. -- #define g_rand_boolean(rand_)
  121. -- Returns a random gboolean from rand_. This corresponds to a unbiased coin toss.
  122. -- rand_ : a GRand.
  123. -- Returns : a random gboolean.
  124. -- ---------------------------------------------------------------------------------
  125. -- g_rand_int ()
  126. -- guint32 g_rand_int (GRand *rand_);
  127. -- Returns the next random guint32 from rand_ equally distributed over the range
  128. -- [0..2^32-1].
  129. -- rand_ : a GRand.
  130. -- Returns : A random number.
  131. -- ---------------------------------------------------------------------------------
  132. -- g_rand_int_range ()
  133. -- gint32 g_rand_int_range (GRand *rand_,
  134. -- gint32 begin,
  135. -- gint32 end);
  136. -- Returns the next random gint32 from rand_ equally distributed over the range
  137. -- [begin..end-1].
  138. -- rand_ : a GRand.
  139. -- begin : lower closed bound of the interval.
  140. -- end : upper open bound of the interval.
  141. -- Returns : A random number.
  142. -- ---------------------------------------------------------------------------------
  143. -- g_rand_double ()
  144. -- gdouble g_rand_double (GRand *rand_);
  145. -- Returns the next random gdouble from rand_ equally distributed over the range
  146. -- [0..1).
  147. -- rand_ : a GRand.
  148. -- Returns : A random number.
  149. -- ---------------------------------------------------------------------------------
  150. -- g_rand_double_range ()
  151. -- gdouble g_rand_double_range (GRand *rand_,
  152. -- gdouble begin,
  153. -- gdouble end);
  154. -- Returns the next random gdouble from rand_ equally distributed over the range
  155. -- [begin..end).
  156. -- rand_ : a GRand.
  157. -- begin : lower closed bound of the interval.
  158. -- end : upper open bound of the interval.
  159. -- Returns : A random number.
  160. -- ---------------------------------------------------------------------------------
  161. -- g_random_set_seed ()
  162. -- void g_random_set_seed (guint32 seed);
  163. -- Sets the seed for the global random number generator, which is used by the
  164. -- g_random_* functions, to seed.
  165. -- seed : a value to reinitialize the global random number generator.
  166. -- ---------------------------------------------------------------------------------
  167. -- g_random_boolean()
  168. -- #define g_random_boolean()
  169. -- Returns a random gboolean. This corresponds to a unbiased coin toss.
  170. -- Returns : a random gboolean.
  171. -- ---------------------------------------------------------------------------------
  172. -- g_random_int ()
  173. -- guint32 g_random_int (void);
  174. -- Return a random guint32 equally distributed over the range [0..2^32-1].
  175. -- Returns : A random number.
  176. -- ---------------------------------------------------------------------------------
  177. -- g_random_int_range ()
  178. -- gint32 g_random_int_range (gint32 begin,
  179. -- gint32 end);
  180. -- Returns a random gint32 equally distributed over the range [begin..end-1].
  181. -- begin : lower closed bound of the interval.
  182. -- end : upper open bound of the interval.
  183. -- Returns : A random number.
  184. -- ---------------------------------------------------------------------------------
  185. -- g_random_double ()
  186. -- gdouble g_random_double (void);
  187. -- Returns a random gdouble equally distributed over the range [0..1).
  188. -- Returns : A random number.
  189. -- ---------------------------------------------------------------------------------
  190. -- g_random_double_range ()
  191. -- gdouble g_random_double_range (gdouble begin,
  192. -- gdouble end);
  193. -- Returns a random gdouble equally distributed over the range [begin..end).
  194. -- begin : lower closed bound of the interval.
  195. -- end : upper open bound of the interval.
  196. -- Returns : A random number.
  197. end -- class GLIB_RANDOM_NUMBERS