glib-Random-Numbers.html   [plain text]


<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Random Numbers</title><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><link rel="home" href="index.html" title="GLib Reference Manual"><link rel="up" href="glib-utilities.html" title="GLib Utilities"><link rel="previous" href="glib-Date-and-Time-Functions.html" title="Date and Time Functions"><link rel="next" href="glib-Hook-Functions.html" title="Hook Functions"><link rel="chapter" href="glib.html" title="GLib Overview"><link rel="refentry" href="glib-building.html" title="Compiling the GLib package"><link rel="refentry" href="glib-cross-compiling.html" title="Cross-compiling the GLib package"><link rel="refentry" href="glib-compiling.html" title="Compiling GLib Applications"><link rel="refentry" href="glib-running.html" title="Running GLib Applications"><link rel="refentry" href="glib-changes.html" title="Changes to GLib"><link rel="refentry" href="glib-resources.html" title="Mailing lists and bug reports"><link rel="chapter" href="glib-fundamentals.html" title="GLib Fundamentals"><link rel="refentry" href="glib-Basic-Types.html" title="Basic Types"><link rel="refentry" href="glib-Limits-of-Basic-Types.html" title="Limits of Basic Types"><link rel="refentry" href="glib-Standard-Macros.html" title="Standard Macros"><link rel="refentry" href="glib-Type-Conversion-Macros.html" title="Type Conversion Macros"><link rel="refentry" href="glib-Byte-Order-Macros.html" title="Byte Order Macros"><link rel="refentry" href="glib-Numerical-Definitions.html" title="Numerical Definitions"><link rel="refentry" href="glib-Miscellaneous-Macros.html" title="Miscellaneous Macros"><link rel="refentry" href="glib-Atomic-Operations.html" title="Atomic Operations"><link rel="chapter" href="glib-core.html" title="GLib Core Application Support"><link rel="refentry" href="glib-The-Main-Event-Loop.html" title="The Main Event Loop"><link rel="refentry" href="glib-Threads.html" title="
Threads"><link rel="refentry" href="glib-Thread-Pools.html" title="Thread Pools"><link rel="refentry" href="glib-Asynchronous-Queues.html" title="Asynchronous Queues"><link rel="refentry" href="glib-Dynamic-Loading-of-Modules.html" title="Dynamic Loading of Modules"><link rel="refentry" href="glib-Memory-Allocation.html" title="Memory Allocation"><link rel="refentry" href="glib-IO-Channels.html" title="IO Channels"><link rel="refentry" href="glib-Error-Reporting.html" title="Error Reporting"><link rel="refentry" href="glib-Warnings-and-Assertions.html" title="Message Output and Debugging Functions"><link rel="refentry" href="glib-Message-Logging.html" title="Message Logging"><link rel="chapter" href="glib-utilities.html" title="GLib Utilities"><link rel="refentry" href="glib-String-Utility-Functions.html" title="String Utility Functions"><link rel="refentry" href="glib-Character-Set-Conversion.html" title="Character Set Conversion"><link rel="refentry" href="glib-Unicode-Manipulation.html" title="Unicode Manipulation"><link rel="refentry" href="glib-I18N.html" title="Internationalization"><link rel="refentry" href="glib-Date-and-Time-Functions.html" title="Date and Time Functions"><link rel="refentry" href="glib-Random-Numbers.html" title="Random Numbers"><link rel="refentry" href="glib-Hook-Functions.html" title="Hook Functions"><link rel="refentry" href="glib-Miscellaneous-Utility-Functions.html" title="Miscellaneous Utility Functions"><link rel="refentry" href="glib-Lexical-Scanner.html" title="Lexical Scanner"><link rel="refentry" href="glib-Automatic-String-Completion.html" title="Automatic String Completion"><link rel="refentry" href="glib-Timers.html" title="Timers"><link rel="refentry" href="glib-Spawning-Processes.html" title="Spawning Processes"><link rel="refentry" href="glib-File-Utilities.html" title="File Utilities"><link rel="refentry" href="glib-Shell-related-Utilities.html" title="Shell-related Utilities"><link rel="refentry" href="glib-Glob-style-pattern-matching.html" title="Glob-style pattern matching"><link rel="refentry" href="glib-Simple-XML-Subset-Parser.html" title="Simple XML Subset Parser"><link rel="refentry" href="glib-Windows-Compatability-Functions.html" title="Windows Compatibility Functions"><link rel="chapter" href="glib-data-types.html" title="GLib Data Types"><link rel="refentry" href="glib-Memory-Chunks.html" title="Memory Chunks"><link rel="refentry" href="glib-Doubly-Linked-Lists.html" title="Doubly-Linked Lists"><link rel="refentry" href="glib-Singly-Linked-Lists.html" title="Singly-Linked Lists"><link rel="refentry" href="glib-Double-ended-Queues.html" title="Double-ended Queues"><link rel="refentry" href="glib-Trash-Stacks.html" title="Trash Stacks"><link rel="refentry" href="glib-Hash-Tables.html" title="Hash Tables"><link rel="refentry" href="glib-Strings.html" title="Strings"><link rel="refentry" href="glib-String-Chunks.html" title="String Chunks"><link rel="refentry" href="glib-Arrays.html" title="Arrays"><link rel="refentry" href="glib-Pointer-Arrays.html" title="Pointer Arrays"><link rel="refentry" href="glib-Byte-Arrays.html" title="Byte Arrays"><link rel="refentry" href="glib-Balanced-Binary-Trees.html" title="Balanced Binary Trees"><link rel="refentry" href="glib-N-ary-Trees.html" title="N-ary Trees"><link rel="refentry" href="glib-Quarks.html" title="Quarks"><link rel="refentry" href="glib-Keyed-Data-Lists.html" title="Keyed Data Lists"><link rel="refentry" href="glib-Datasets.html" title="Datasets"><link rel="refentry" href="glib-Relations-and-Tuples.html" title="Relations and Tuples"><link rel="refentry" href="glib-Caches.html" title="Caches"><link rel="refentry" href="glib-Memory-Allocators.html" title="Memory Allocators"><link rel="chapter" href="tools.html" title="GLib Tools"><link rel="refentry" href="glib-gettextize.html" title="glib-gettextize"><link rel="index" href="ix01.html" title="Index"><link rel="section" href="glib-Random-Numbers.html#id3163686" title="Description"><link rel="section" href="glib-Random-Numbers.html#id3163832" title="Details"><meta name="generator" content="GTK-Doc V1.2 (XML mode)"><link rel="stylesheet" href="style.css" type="text/css"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table class="navigation" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle"><td><a accesskey="p" href="glib-Date-and-Time-Functions.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td><td><a accesskey="u" href="glib-utilities.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td><td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td><th width="100%" align="center">GLib Reference Manual</th><td><a accesskey="n" href="glib-Hook-Functions.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td></tr></table><div class="refentry" lang="en"><a name="glib-Random-Numbers"></a><div class="titlepage"><div></div><div></div></div><div class="refnamediv"><h2><span class="refentrytitle">Random Numbers</span></h2><p>Random Numbers &#8212; pseudo-random number generator.</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">

#include &lt;glib.h&gt;


struct      <a href="glib-Random-Numbers.html#GRand">GRand</a>;
<a href="glib-Random-Numbers.html#GRand">GRand</a>*      <a href="glib-Random-Numbers.html#g-rand-new-with-seed">g_rand_new_with_seed</a>            (<a href="glib-Basic-Types.html#guint32">guint32</a> seed);
<a href="glib-Random-Numbers.html#GRand">GRand</a>*      <a href="glib-Random-Numbers.html#g-rand-new-with-seed-array">g_rand_new_with_seed_array</a>      (const <a href="glib-Basic-Types.html#guint32">guint32</a> *seed,
                                             <a href="glib-Basic-Types.html#guint">guint</a> seed_length);
<a href="glib-Random-Numbers.html#GRand">GRand</a>*      <a href="glib-Random-Numbers.html#g-rand-new">g_rand_new</a>                      (void);
<a href="glib-Random-Numbers.html#GRand">GRand</a>*      <a href="glib-Random-Numbers.html#g-rand-copy">g_rand_copy</a>                     (<a href="glib-Random-Numbers.html#GRand">GRand</a> *rand_);
void        <a href="glib-Random-Numbers.html#g-rand-free">g_rand_free</a>                     (<a href="glib-Random-Numbers.html#GRand">GRand</a> *rand_);
void        <a href="glib-Random-Numbers.html#g-rand-set-seed">g_rand_set_seed</a>                 (<a href="glib-Random-Numbers.html#GRand">GRand</a> *rand_,
                                             <a href="glib-Basic-Types.html#guint32">guint32</a> seed);
void        <a href="glib-Random-Numbers.html#g-rand-set-seed-array">g_rand_set_seed_array</a>           (<a href="glib-Random-Numbers.html#GRand">GRand</a> *rand_,
                                             const <a href="glib-Basic-Types.html#guint32">guint32</a> *seed,
                                             <a href="glib-Basic-Types.html#guint">guint</a> seed_length);
#define     <a href="glib-Random-Numbers.html#g-rand-boolean">g_rand_boolean</a>                  (rand_)
<a href="glib-Basic-Types.html#guint32">guint32</a>     <a href="glib-Random-Numbers.html#g-rand-int">g_rand_int</a>                      (<a href="glib-Random-Numbers.html#GRand">GRand</a> *rand_);
<a href="glib-Basic-Types.html#gint32">gint32</a>      <a href="glib-Random-Numbers.html#g-rand-int-range">g_rand_int_range</a>                (<a href="glib-Random-Numbers.html#GRand">GRand</a> *rand_,
                                             <a href="glib-Basic-Types.html#gint32">gint32</a> begin,
                                             <a href="glib-Basic-Types.html#gint32">gint32</a> end);
<a href="glib-Basic-Types.html#gdouble">gdouble</a>     <a href="glib-Random-Numbers.html#g-rand-double">g_rand_double</a>                   (<a href="glib-Random-Numbers.html#GRand">GRand</a> *rand_);
<a href="glib-Basic-Types.html#gdouble">gdouble</a>     <a href="glib-Random-Numbers.html#g-rand-double-range">g_rand_double_range</a>             (<a href="glib-Random-Numbers.html#GRand">GRand</a> *rand_,
                                             <a href="glib-Basic-Types.html#gdouble">gdouble</a> begin,
                                             <a href="glib-Basic-Types.html#gdouble">gdouble</a> end);
void        <a href="glib-Random-Numbers.html#g-random-set-seed">g_random_set_seed</a>               (<a href="glib-Basic-Types.html#guint32">guint32</a> seed);
#define     <a href="glib-Random-Numbers.html#g-random-boolean">g_random_boolean</a>                ()
<a href="glib-Basic-Types.html#guint32">guint32</a>     <a href="glib-Random-Numbers.html#g-random-int">g_random_int</a>                    (void);
<a href="glib-Basic-Types.html#gint32">gint32</a>      <a href="glib-Random-Numbers.html#g-random-int-range">g_random_int_range</a>              (<a href="glib-Basic-Types.html#gint32">gint32</a> begin,
                                             <a href="glib-Basic-Types.html#gint32">gint32</a> end);
<a href="glib-Basic-Types.html#gdouble">gdouble</a>     <a href="glib-Random-Numbers.html#g-random-double">g_random_double</a>                 (void);
<a href="glib-Basic-Types.html#gdouble">gdouble</a>     <a href="glib-Random-Numbers.html#g-random-double-range">g_random_double_range</a>           (<a href="glib-Basic-Types.html#gdouble">gdouble</a> begin,
                                             <a href="glib-Basic-Types.html#gdouble">gdouble</a> end);
</pre></div><div class="refsect1" lang="en"><a name="id3163686"></a><h2>Description</h2><p>
The following functions allow you to use a portable, fast and good
pseudo-random number generator (PRNG). It uses the Mersenne Twister
PRNG, which was originally developed by Makoto Matsumoto and Takuji
Nishimura. Further information can be found at <a href="http://www.math.keio.ac.jp/~matumoto/emt.html" target="_top">www.math.keio.ac.jp/~matumoto/emt.html</a>.
</p><p>
If you just need a random number, you simply call the 
<tt class="function">g_random_*</tt> functions, which will create a globally 
used <a href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a> and use the according <tt class="function">g_rand_*</tt> functions 
internally. Whenever you need a stream of reproducible random numbers, you 
better create a <a href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a> yourself and use the <tt class="function">g_rand_*</tt> 
functions directly, which will also be slightly faster. Initializing a <a href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a> 
with a certain seed will produce exactly the same series of random numbers 
on all platforms. This can thus be used as a seed for e.g. games.
</p><p>
The <tt class="function">g_rand*_range</tt> functions will return high quality
equally distributed random numbers, whereas for example the
<tt class="literal">(<a href="glib-Random-Numbers.html#g-random-int"><tt class="function">g_random_int()</tt></a>%max)</tt> approach often doesn't
yield equally distributed numbers.
</p><p>
GLib changed the seeding algorithm for the pseudo-random number
generator Mersenne Twister, as used by <span class="structname">GRand</span>
and <span class="structname">GRandom</span>. This was necessary, because some
seeds would yield very bad pseudo-random streams.  Also the
pseudo-random integers generated by
<tt class="function">g_rand*<tt class="function">_int_range()</tt></tt> will have a
slightly better equal distribution with the new version of GLib.
</p><p>
The original seeding and generation algorithms, as found in GLib 2.0.x,
can be used instead of the new ones by setting the environment variable
<tt class="envar">G_RANDOM_VERSION</tt> to the value of '2.0'. Use the
GLib-2.0 algorithms only if you have sequences of numbers generated
with Glib-2.0 that you need to reproduce exactly.
</p></div><div class="refsect1" lang="en"><a name="id3163832"></a><h2>Details</h2><div class="refsect2" lang="en"><a name="id3163838"></a><h3><a name="GRand"></a>struct GRand</h3><a class="indexterm" name="id3163849"></a><pre class="programlisting">struct GRand;</pre><p>
The <a href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a> struct is an opaque data structure. It should only be
accessed through the <tt class="function">g_rand_*</tt> functions.
</p></div><hr><div class="refsect2" lang="en"><a name="id3163879"></a><h3><a name="g-rand-new-with-seed"></a>g_rand_new_with_seed ()</h3><a class="indexterm" name="id3163891"></a><pre class="programlisting"><a href="glib-Random-Numbers.html#GRand">GRand</a>*      g_rand_new_with_seed            (<a href="glib-Basic-Types.html#guint32">guint32</a> seed);</pre><p>
Creates a new random number generator initialized with <i class="parameter"><tt>seed</tt></i>.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>seed</tt></i> :</span></td><td> a value to initialize the random number generator.
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> the new <a href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a>.
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3163963"></a><h3><a name="g-rand-new-with-seed-array"></a>g_rand_new_with_seed_array ()</h3><a class="indexterm" name="id3163976"></a><pre class="programlisting"><a href="glib-Random-Numbers.html#GRand">GRand</a>*      g_rand_new_with_seed_array      (const <a href="glib-Basic-Types.html#guint32">guint32</a> *seed,
                                             <a href="glib-Basic-Types.html#guint">guint</a> seed_length);</pre><p>
Creates a new random number generator initialized with <i class="parameter"><tt>seed</tt></i>.</p><p>

</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>seed</tt></i> :</span></td><td> an array of seeds to initialize the random number generator.
</td></tr><tr><td><span class="term"><i class="parameter"><tt>seed_length</tt></i> :</span></td><td> an array of seeds to initialize the random number generator.
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> the new <a href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a>.

</td></tr></tbody></table></div><p>Since  2.4
</p></div><hr><div class="refsect2" lang="en"><a name="id3164077"></a><h3><a name="g-rand-new"></a>g_rand_new ()</h3><a class="indexterm" name="id3164088"></a><pre class="programlisting"><a href="glib-Random-Numbers.html#GRand">GRand</a>*      g_rand_new                      (void);</pre><p>
Creates a new random number generator initialized with a seed taken
either from <tt class="filename">/dev/urandom</tt> (if existing) or from 
the current time (as a fallback).</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> the new <a href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a>.
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3164141"></a><h3><a name="g-rand-copy"></a>g_rand_copy ()</h3><a class="indexterm" name="id3164152"></a><pre class="programlisting"><a href="glib-Random-Numbers.html#GRand">GRand</a>*      g_rand_copy                     (<a href="glib-Random-Numbers.html#GRand">GRand</a> *rand_);</pre><p>
Copies a <a href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a> into a new one with the same exact state as before.
This way you can take a snapshot of the random number generator for
replaying later.</p><p>

</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>rand_</tt></i> :</span></td><td> a <a href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a>.
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> the new <a href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a>.

</td></tr></tbody></table></div><p>Since  2.4
</p></div><hr><div class="refsect2" lang="en"><a name="id3164241"></a><h3><a name="g-rand-free"></a>g_rand_free ()</h3><a class="indexterm" name="id3164252"></a><pre class="programlisting">void        g_rand_free                     (<a href="glib-Random-Numbers.html#GRand">GRand</a> *rand_);</pre><p>
Frees the memory allocated for the <a href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a>.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>rand_</tt></i> :</span></td><td> a <a href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a>.
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3164314"></a><h3><a name="g-rand-set-seed"></a>g_rand_set_seed ()</h3><a class="indexterm" name="id3164326"></a><pre class="programlisting">void        g_rand_set_seed                 (<a href="glib-Random-Numbers.html#GRand">GRand</a> *rand_,
                                             <a href="glib-Basic-Types.html#guint32">guint32</a> seed);</pre><p>
Sets the seed for the random number generator <a href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a> to <i class="parameter"><tt>seed</tt></i>.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>rand_</tt></i> :</span></td><td> a <a href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a>.
</td></tr><tr><td><span class="term"><i class="parameter"><tt>seed</tt></i> :</span></td><td> a value to reinitialize the random number generator.
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3164417"></a><h3><a name="g-rand-set-seed-array"></a>g_rand_set_seed_array ()</h3><a class="indexterm" name="id3164429"></a><pre class="programlisting">void        g_rand_set_seed_array           (<a href="glib-Random-Numbers.html#GRand">GRand</a> *rand_,
                                             const <a href="glib-Basic-Types.html#guint32">guint32</a> *seed,
                                             <a href="glib-Basic-Types.html#guint">guint</a> seed_length);</pre><p>
Initializes the random number generator by an array of
longs.  Array can be of arbitrary size, though only the
first 624 values are taken.  This function is useful
if you have many low entropy seeds, or if you require more then
32bits of actual entropy for your application.</p><p>

</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>rand_</tt></i> :</span></td><td> a <a href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a>.
</td></tr><tr><td><span class="term"><i class="parameter"><tt>seed</tt></i> :</span></td><td> array to initialize with
</td></tr><tr><td><span class="term"><i class="parameter"><tt>seed_length</tt></i> :</span></td><td> length of array
</td></tr></tbody></table></div><p>Since  2.4
</p></div><hr><div class="refsect2" lang="en"><a name="id3164538"></a><h3><a name="g-rand-boolean"></a>g_rand_boolean()</h3><a class="indexterm" name="id3164549"></a><pre class="programlisting">#define     g_rand_boolean(rand_)</pre><p>
Returns a random <a href="glib-Basic-Types.html#gboolean"><span class="type">gboolean</span></a> from <i class="parameter"><tt>rand_</tt></i>. This corresponds to a unbiased
coin toss.
</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>rand_</tt></i> :</span></td><td>a <a href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a>.
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td>a random <a href="glib-Basic-Types.html#gboolean"><span class="type">gboolean</span></a>.


</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3164624"></a><h3><a name="g-rand-int"></a>g_rand_int ()</h3><a class="indexterm" name="id3164634"></a><pre class="programlisting"><a href="glib-Basic-Types.html#guint32">guint32</a>     g_rand_int                      (<a href="glib-Random-Numbers.html#GRand">GRand</a> *rand_);</pre><p>
Returns the next random <a href="glib-Basic-Types.html#guint32"><span class="type">guint32</span></a> from <i class="parameter"><tt>rand_</tt></i> equally distributed over
the range [0..2^32-1].</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>rand_</tt></i> :</span></td><td> a <a href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a>.
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> A random number.
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3164714"></a><h3><a name="g-rand-int-range"></a>g_rand_int_range ()</h3><a class="indexterm" name="id3164725"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gint32">gint32</a>      g_rand_int_range                (<a href="glib-Random-Numbers.html#GRand">GRand</a> *rand_,
                                             <a href="glib-Basic-Types.html#gint32">gint32</a> begin,
                                             <a href="glib-Basic-Types.html#gint32">gint32</a> end);</pre><p>
Returns the next random <a href="glib-Basic-Types.html#gint32"><span class="type">gint32</span></a> from <i class="parameter"><tt>rand_</tt></i> equally distributed over
the range [<i class="parameter"><tt>begin</tt></i>..<i class="parameter"><tt>end</tt></i>-1].</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>rand_</tt></i> :</span></td><td> a <a href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a>.
</td></tr><tr><td><span class="term"><i class="parameter"><tt>begin</tt></i> :</span></td><td> lower closed bound of the interval.
</td></tr><tr><td><span class="term"><i class="parameter"><tt>end</tt></i> :</span></td><td> upper open bound of the interval.
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> A random number.
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3164860"></a><h3><a name="g-rand-double"></a>g_rand_double ()</h3><a class="indexterm" name="id3164871"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gdouble">gdouble</a>     g_rand_double                   (<a href="glib-Random-Numbers.html#GRand">GRand</a> *rand_);</pre><p>
Returns the next random <a href="glib-Basic-Types.html#gdouble"><span class="type">gdouble</span></a> from <i class="parameter"><tt>rand_</tt></i> equally distributed over
the range [0..1).</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>rand_</tt></i> :</span></td><td> a <a href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a>.
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> A random number.
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3164951"></a><h3><a name="g-rand-double-range"></a>g_rand_double_range ()</h3><a class="indexterm" name="id3164963"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gdouble">gdouble</a>     g_rand_double_range             (<a href="glib-Random-Numbers.html#GRand">GRand</a> *rand_,
                                             <a href="glib-Basic-Types.html#gdouble">gdouble</a> begin,
                                             <a href="glib-Basic-Types.html#gdouble">gdouble</a> end);</pre><p>
Returns the next random <a href="glib-Basic-Types.html#gdouble"><span class="type">gdouble</span></a> from <i class="parameter"><tt>rand_</tt></i> equally distributed over
the range [<i class="parameter"><tt>begin</tt></i>..<i class="parameter"><tt>end</tt></i>).</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>rand_</tt></i> :</span></td><td> a <a href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a>.
</td></tr><tr><td><span class="term"><i class="parameter"><tt>begin</tt></i> :</span></td><td> lower closed bound of the interval.
</td></tr><tr><td><span class="term"><i class="parameter"><tt>end</tt></i> :</span></td><td> upper open bound of the interval.
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> A random number.
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3165097"></a><h3><a name="g-random-set-seed"></a>g_random_set_seed ()</h3><a class="indexterm" name="id3165109"></a><pre class="programlisting">void        g_random_set_seed               (<a href="glib-Basic-Types.html#guint32">guint32</a> seed);</pre><p>
Sets the seed for the global random number generator, which is used
by the <tt class="function">g_random_*</tt> functions, to <i class="parameter"><tt>seed</tt></i>.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>seed</tt></i> :</span></td><td> a value to reinitialize the global random number generator.
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3165170"></a><h3><a name="g-random-boolean"></a>g_random_boolean()</h3><a class="indexterm" name="id3165181"></a><pre class="programlisting">#define     g_random_boolean()</pre><p>
Returns a random <a href="glib-Basic-Types.html#gboolean"><span class="type">gboolean</span></a>. This corresponds to a unbiased coin toss.
</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td>a random <a href="glib-Basic-Types.html#gboolean"><span class="type">gboolean</span></a>.


</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3165228"></a><h3><a name="g-random-int"></a>g_random_int ()</h3><a class="indexterm" name="id3165239"></a><pre class="programlisting"><a href="glib-Basic-Types.html#guint32">guint32</a>     g_random_int                    (void);</pre><p>
Return a random <a href="glib-Basic-Types.html#guint32"><span class="type">guint32</span></a> equally distributed over the range
[0..2^32-1].</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> A random number.
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3165285"></a><h3><a name="g-random-int-range"></a>g_random_int_range ()</h3><a class="indexterm" name="id3165297"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gint32">gint32</a>      g_random_int_range              (<a href="glib-Basic-Types.html#gint32">gint32</a> begin,
                                             <a href="glib-Basic-Types.html#gint32">gint32</a> end);</pre><p>
Returns a random <a href="glib-Basic-Types.html#gint32"><span class="type">gint32</span></a> equally distributed over the range
[<i class="parameter"><tt>begin</tt></i>..<i class="parameter"><tt>end</tt></i>-1].</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>begin</tt></i> :</span></td><td> lower closed bound of the interval.
</td></tr><tr><td><span class="term"><i class="parameter"><tt>end</tt></i> :</span></td><td> upper open bound of the interval.
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> A random number.
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3165396"></a><h3><a name="g-random-double"></a>g_random_double ()</h3><a class="indexterm" name="id3165407"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gdouble">gdouble</a>     g_random_double                 (void);</pre><p>
Returns a random <a href="glib-Basic-Types.html#gdouble"><span class="type">gdouble</span></a> equally distributed over the range [0..1).</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> A random number.
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3165453"></a><h3><a name="g-random-double-range"></a>g_random_double_range ()</h3><a class="indexterm" name="id3165465"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gdouble">gdouble</a>     g_random_double_range           (<a href="glib-Basic-Types.html#gdouble">gdouble</a> begin,
                                             <a href="glib-Basic-Types.html#gdouble">gdouble</a> end);</pre><p>
Returns a random <a href="glib-Basic-Types.html#gdouble"><span class="type">gdouble</span></a> equally distributed over the range [<i class="parameter"><tt>begin</tt></i>..<i class="parameter"><tt>end</tt></i>).</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>begin</tt></i> :</span></td><td> lower closed bound of the interval.
</td></tr><tr><td><span class="term"><i class="parameter"><tt>end</tt></i> :</span></td><td> upper open bound of the interval.
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> A random number.
</td></tr></tbody></table></div></div></div></div><table class="navigation" width="100%" summary="Navigation footer" cellpadding="2" cellspacing="0"><tr valign="middle"><td align="left"><a accesskey="p" href="glib-Date-and-Time-Functions.html"><b>&lt;&lt; Date and Time Functions</b></a></td><td align="right"><a accesskey="n" href="glib-Hook-Functions.html"><b>Hook Functions &gt;&gt;</b></a></td></tr></table></body></html>