blob: e5ef32997f63d3b7d85754ef6b0ee24d74c4e2bb [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Random Numbers: GLib Reference Manual</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="index.html" title="GLib Reference Manual">
<link rel="up" href="glib-utilities.html" title="GLib Utilities">
<link rel="prev" href="glib-GDateTime.html" title="GDateTime">
<link rel="next" href="glib-Hook-Functions.html" title="Hook Functions">
<meta name="generator" content="GTK-Doc V1.25.1 (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" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle">
<td width="100%" align="left" class="shortcuts">
<a href="#" class="shortcut">Top</a><span id="nav_description">  <span class="dim">|</span> 
<a href="#glib-Random-Numbers.description" class="shortcut">Description</a></span>
</td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
<td><a accesskey="u" href="glib-utilities.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td>
<td><a accesskey="p" href="glib-GDateTime.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
<td><a accesskey="n" href="glib-Hook-Functions.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
</tr></table>
<div class="refentry">
<a name="glib-Random-Numbers"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2><span class="refentrytitle"><a name="glib-Random-Numbers.top_of_page"></a>Random Numbers</span></h2>
<p>Random Numbers — pseudo-random number generator</p>
</td>
<td class="gallery_image" valign="top" align="right"></td>
</tr></table></div>
<div class="refsect1">
<a name="glib-Random-Numbers.functions"></a><h2>Functions</h2>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="functions_return">
<col class="functions_name">
</colgroup>
<tbody>
<tr>
<td class="function_type">
<a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="returnvalue">GRand</span></a> *
</td>
<td class="function_name">
<a class="link" href="glib-Random-Numbers.html#g-rand-new-with-seed" title="g_rand_new_with_seed ()">g_rand_new_with_seed</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="returnvalue">GRand</span></a> *
</td>
<td class="function_name">
<a class="link" href="glib-Random-Numbers.html#g-rand-new-with-seed-array" title="g_rand_new_with_seed_array ()">g_rand_new_with_seed_array</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="returnvalue">GRand</span></a> *
</td>
<td class="function_name">
<a class="link" href="glib-Random-Numbers.html#g-rand-new" title="g_rand_new ()">g_rand_new</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="returnvalue">GRand</span></a> *
</td>
<td class="function_name">
<a class="link" href="glib-Random-Numbers.html#g-rand-copy" title="g_rand_copy ()">g_rand_copy</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-Random-Numbers.html#g-rand-free" title="g_rand_free ()">g_rand_free</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-Random-Numbers.html#g-rand-set-seed" title="g_rand_set_seed ()">g_rand_set_seed</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-Random-Numbers.html#g-rand-set-seed-array" title="g_rand_set_seed_array ()">g_rand_set_seed_array</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="define_keyword">#define</td>
<td class="function_name">
<a class="link" href="glib-Random-Numbers.html#g-rand-boolean" title="g_rand_boolean()">g_rand_boolean</a><span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#guint32" title="guint32"><span class="returnvalue">guint32</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-Random-Numbers.html#g-rand-int" title="g_rand_int ()">g_rand_int</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#gint32" title="gint32"><span class="returnvalue">gint32</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-Random-Numbers.html#g-rand-int-range" title="g_rand_int_range ()">g_rand_int_range</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#gdouble" title="gdouble"><span class="returnvalue">gdouble</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-Random-Numbers.html#g-rand-double" title="g_rand_double ()">g_rand_double</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#gdouble" title="gdouble"><span class="returnvalue">gdouble</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-Random-Numbers.html#g-rand-double-range" title="g_rand_double_range ()">g_rand_double_range</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-Random-Numbers.html#g-random-set-seed" title="g_random_set_seed ()">g_random_set_seed</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="define_keyword">#define</td>
<td class="function_name"><a class="link" href="glib-Random-Numbers.html#g-random-boolean" title="g_random_boolean">g_random_boolean</a></td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#guint32" title="guint32"><span class="returnvalue">guint32</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-Random-Numbers.html#g-random-int" title="g_random_int ()">g_random_int</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#gint32" title="gint32"><span class="returnvalue">gint32</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-Random-Numbers.html#g-random-int-range" title="g_random_int_range ()">g_random_int_range</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#gdouble" title="gdouble"><span class="returnvalue">gdouble</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-Random-Numbers.html#g-random-double" title="g_random_double ()">g_random_double</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#gdouble" title="gdouble"><span class="returnvalue">gdouble</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-Random-Numbers.html#g-random-double-range" title="g_random_double_range ()">g_random_double_range</a> <span class="c_punctuation">()</span>
</td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect1">
<a name="glib-Random-Numbers.other"></a><h2>Types and Values</h2>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="name">
<col class="description">
</colgroup>
<tbody><tr>
<td class="datatype_keyword"> </td>
<td class="function_name"><a class="link" href="glib-Random-Numbers.html#GRand" title="GRand">GRand</a></td>
</tr></tbody>
</table></div>
</div>
<div class="refsect1">
<a name="glib-Random-Numbers.includes"></a><h2>Includes</h2>
<pre class="synopsis">#include &lt;glib.h&gt;
</pre>
</div>
<div class="refsect1">
<a name="glib-Random-Numbers.description"></a><h2>Description</h2>
<p>The following functions allow you to use a portable, fast and good
pseudo-random number generator (PRNG).</p>
<p>Do not use this API for cryptographic purposes such as key
generation, nonces, salts or one-time pads.</p>
<p>This PRNG is suitable for non-cryptographic use such as in games
(shuffling a card deck, generating levels), generating data for
a test suite, etc. If you need random data for cryptographic
purposes, it is recommended to use platform-specific APIs such
as <code class="literal">/dev/random</code> on UNIX, or <code class="function">CryptGenRandom()</code> on Windows.</p>
<p>GRand uses the Mersenne Twister PRNG, which was originally
developed by Makoto Matsumoto and Takuji Nishimura. Further
information can be found at
<a class="ulink" href="http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html" target="_top">this page</a>.</p>
<p>If you just need a random number, you simply call the g_random_*
functions, which will create a globally used <a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="type">GRand</span></a> and use the
according g_rand_* functions internally. Whenever you need a
stream of reproducible random numbers, you better create a
<a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="type">GRand</span></a> yourself and use the g_rand_* functions directly, which
will also be slightly faster. Initializing a <a class="link" href="glib-Random-Numbers.html#GRand" title="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 g_rand*_range functions will return high quality equally
distributed random numbers, whereas for example the
<code class="literal">(<a class="link" href="glib-Random-Numbers.html#g-random-int" title="g_random_int ()"><code class="function">g_random_int()</code></a>%max)</code> 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 <a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="type">GRand</span></a>. This was necessary,
because some seeds would yield very bad pseudo-random streams.
Also the pseudo-random integers generated by g_rand*_int_range()
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 <code class="literal">G_RANDOM_VERSION</code> 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">
<a name="glib-Random-Numbers.functions_details"></a><h2>Functions</h2>
<div class="refsect2">
<a name="g-rand-new-with-seed"></a><h3>g_rand_new_with_seed ()</h3>
<pre class="programlisting"><a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="returnvalue">GRand</span></a> *
g_rand_new_with_seed (<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#guint32" title="guint32"><span class="type">guint32</span></a> seed</code></em>);</pre>
<p>Creates a new random number generator initialized with <em class="parameter"><code>seed</code></em>
.</p>
<div class="refsect3">
<a name="g-rand-new-with-seed.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody><tr>
<td class="parameter_name"><p>seed</p></td>
<td class="parameter_description"><p>a value to initialize the random number generator</p></td>
<td class="parameter_annotations"> </td>
</tr></tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-rand-new-with-seed.returns"></a><h4>Returns</h4>
<p> the new <a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="type">GRand</span></a></p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-rand-new-with-seed-array"></a><h3>g_rand_new_with_seed_array ()</h3>
<pre class="programlisting"><a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="returnvalue">GRand</span></a> *
g_rand_new_with_seed_array (<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#guint32" title="guint32"><span class="type">guint32</span></a> *seed</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#guint" title="guint ()"><span class="type">guint</span></a> seed_length</code></em>);</pre>
<p>Creates a new random number generator initialized with <em class="parameter"><code>seed</code></em>
.</p>
<div class="refsect3">
<a name="g-rand-new-with-seed-array.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>seed</p></td>
<td class="parameter_description"><p>an array of seeds to initialize the random number generator</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>seed_length</p></td>
<td class="parameter_description"><p>an array of seeds to initialize the random number
generator</p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-rand-new-with-seed-array.returns"></a><h4>Returns</h4>
<p> the new <a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="type">GRand</span></a></p>
</div>
<p class="since">Since: <a class="link" href="api-index-2-4.html#api-index-2.4">2.4</a></p>
</div>
<hr>
<div class="refsect2">
<a name="g-rand-new"></a><h3>g_rand_new ()</h3>
<pre class="programlisting"><a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="returnvalue">GRand</span></a> *
g_rand_new (<em class="parameter"><code><span class="type">void</span></code></em>);</pre>
<p>Creates a new random number generator initialized with a seed taken
either from <code class="literal">/dev/urandom</code> (if existing) or from the current time
(as a fallback).</p>
<p>On Windows, the seed is taken from <code class="function">rand_s()</code>.</p>
<div class="refsect3">
<a name="g-rand-new.returns"></a><h4>Returns</h4>
<p> the new <a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="type">GRand</span></a></p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-rand-copy"></a><h3>g_rand_copy ()</h3>
<pre class="programlisting"><a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="returnvalue">GRand</span></a> *
g_rand_copy (<em class="parameter"><code><a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="type">GRand</span></a> *rand_</code></em>);</pre>
<p>Copies a <a class="link" href="glib-Random-Numbers.html#GRand" title="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>
<div class="refsect3">
<a name="g-rand-copy.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody><tr>
<td class="parameter_name"><p>rand_</p></td>
<td class="parameter_description"><p>a <a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="type">GRand</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr></tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-rand-copy.returns"></a><h4>Returns</h4>
<p> the new <a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="type">GRand</span></a></p>
</div>
<p class="since">Since: <a class="link" href="api-index-2-4.html#api-index-2.4">2.4</a></p>
</div>
<hr>
<div class="refsect2">
<a name="g-rand-free"></a><h3>g_rand_free ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>
g_rand_free (<em class="parameter"><code><a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="type">GRand</span></a> *rand_</code></em>);</pre>
<p>Frees the memory allocated for the <a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="type">GRand</span></a>.</p>
<div class="refsect3">
<a name="g-rand-free.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody><tr>
<td class="parameter_name"><p>rand_</p></td>
<td class="parameter_description"><p>a <a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="type">GRand</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr></tbody>
</table></div>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-rand-set-seed"></a><h3>g_rand_set_seed ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>
g_rand_set_seed (<em class="parameter"><code><a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="type">GRand</span></a> *rand_</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#guint32" title="guint32"><span class="type">guint32</span></a> seed</code></em>);</pre>
<p>Sets the seed for the random number generator <a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="type">GRand</span></a> to <em class="parameter"><code>seed</code></em>
.</p>
<div class="refsect3">
<a name="g-rand-set-seed.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>rand_</p></td>
<td class="parameter_description"><p>a <a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="type">GRand</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>seed</p></td>
<td class="parameter_description"><p>a value to reinitialize the random number generator</p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-rand-set-seed-array"></a><h3>g_rand_set_seed_array ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>
g_rand_set_seed_array (<em class="parameter"><code><a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="type">GRand</span></a> *rand_</code></em>,
<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#guint32" title="guint32"><span class="type">guint32</span></a> *seed</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#guint" title="guint ()"><span class="type">guint</span></a> seed_length</code></em>);</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 32 bits of actual entropy for
your application.</p>
<div class="refsect3">
<a name="g-rand-set-seed-array.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>rand_</p></td>
<td class="parameter_description"><p>a <a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="type">GRand</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>seed</p></td>
<td class="parameter_description"><p>array to initialize with</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>seed_length</p></td>
<td class="parameter_description"><p>length of array</p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<p class="since">Since: <a class="link" href="api-index-2-4.html#api-index-2.4">2.4</a></p>
</div>
<hr>
<div class="refsect2">
<a name="g-rand-boolean"></a><h3>g_rand_boolean()</h3>
<pre class="programlisting">#define g_rand_boolean(rand_)</pre>
<p>Returns a random <a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="type">gboolean</span></a> from <em class="parameter"><code>rand_</code></em>
.
This corresponds to a unbiased coin toss.</p>
<div class="refsect3">
<a name="g-rand-boolean.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody><tr>
<td class="parameter_name"><p>rand_</p></td>
<td class="parameter_description"><p>a <a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="type">GRand</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr></tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-rand-boolean.returns"></a><h4>Returns</h4>
<p> a random <a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="type">gboolean</span></a></p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-rand-int"></a><h3>g_rand_int ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#guint32" title="guint32"><span class="returnvalue">guint32</span></a>
g_rand_int (<em class="parameter"><code><a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="type">GRand</span></a> *rand_</code></em>);</pre>
<p>Returns the next random <a class="link" href="glib-Basic-Types.html#guint32" title="guint32"><span class="type">guint32</span></a> from <em class="parameter"><code>rand_</code></em>
equally distributed over
the range [0..2^32-1].</p>
<div class="refsect3">
<a name="g-rand-int.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody><tr>
<td class="parameter_name"><p>rand_</p></td>
<td class="parameter_description"><p>a <a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="type">GRand</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr></tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-rand-int.returns"></a><h4>Returns</h4>
<p> a random number</p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-rand-int-range"></a><h3>g_rand_int_range ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gint32" title="gint32"><span class="returnvalue">gint32</span></a>
g_rand_int_range (<em class="parameter"><code><a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="type">GRand</span></a> *rand_</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint32" title="gint32"><span class="type">gint32</span></a> begin</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint32" title="gint32"><span class="type">gint32</span></a> end</code></em>);</pre>
<p>Returns the next random <a class="link" href="glib-Basic-Types.html#gint32" title="gint32"><span class="type">gint32</span></a> from <em class="parameter"><code>rand_</code></em>
equally distributed over
the range [<em class="parameter"><code>begin</code></em>
..<em class="parameter"><code>end</code></em>
-1].</p>
<div class="refsect3">
<a name="g-rand-int-range.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>rand_</p></td>
<td class="parameter_description"><p>a <a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="type">GRand</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>begin</p></td>
<td class="parameter_description"><p>lower closed bound of the interval</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>end</p></td>
<td class="parameter_description"><p>upper open bound of the interval</p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-rand-int-range.returns"></a><h4>Returns</h4>
<p> a random number</p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-rand-double"></a><h3>g_rand_double ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gdouble" title="gdouble"><span class="returnvalue">gdouble</span></a>
g_rand_double (<em class="parameter"><code><a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="type">GRand</span></a> *rand_</code></em>);</pre>
<p>Returns the next random <a class="link" href="glib-Basic-Types.html#gdouble" title="gdouble"><span class="type">gdouble</span></a> from <em class="parameter"><code>rand_</code></em>
equally distributed over
the range [0..1).</p>
<div class="refsect3">
<a name="g-rand-double.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody><tr>
<td class="parameter_name"><p>rand_</p></td>
<td class="parameter_description"><p>a <a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="type">GRand</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr></tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-rand-double.returns"></a><h4>Returns</h4>
<p> a random number</p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-rand-double-range"></a><h3>g_rand_double_range ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gdouble" title="gdouble"><span class="returnvalue">gdouble</span></a>
g_rand_double_range (<em class="parameter"><code><a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="type">GRand</span></a> *rand_</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gdouble" title="gdouble"><span class="type">gdouble</span></a> begin</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gdouble" title="gdouble"><span class="type">gdouble</span></a> end</code></em>);</pre>
<p>Returns the next random <a class="link" href="glib-Basic-Types.html#gdouble" title="gdouble"><span class="type">gdouble</span></a> from <em class="parameter"><code>rand_</code></em>
equally distributed over
the range [<em class="parameter"><code>begin</code></em>
..<em class="parameter"><code>end</code></em>
).</p>
<div class="refsect3">
<a name="g-rand-double-range.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>rand_</p></td>
<td class="parameter_description"><p>a <a class="link" href="glib-Random-Numbers.html#GRand" title="GRand"><span class="type">GRand</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>begin</p></td>
<td class="parameter_description"><p>lower closed bound of the interval</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>end</p></td>
<td class="parameter_description"><p>upper open bound of the interval</p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-rand-double-range.returns"></a><h4>Returns</h4>
<p> a random number</p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-random-set-seed"></a><h3>g_random_set_seed ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>
g_random_set_seed (<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#guint32" title="guint32"><span class="type">guint32</span></a> seed</code></em>);</pre>
<p>Sets the seed for the global random number generator, which is used
by the g_random_* functions, to <em class="parameter"><code>seed</code></em>
.</p>
<div class="refsect3">
<a name="g-random-set-seed.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody><tr>
<td class="parameter_name"><p>seed</p></td>
<td class="parameter_description"><p>a value to reinitialize the global random number generator</p></td>
<td class="parameter_annotations"> </td>
</tr></tbody>
</table></div>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-random-boolean"></a><h3>g_random_boolean</h3>
<pre class="programlisting">#define g_random_boolean()</pre>
<p>Returns a random <a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="type">gboolean</span></a>.
This corresponds to a unbiased coin toss.</p>
<div class="refsect3">
<a name="g-random-boolean.returns"></a><h4>Returns</h4>
<p> a random <a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="type">gboolean</span></a></p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-random-int"></a><h3>g_random_int ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#guint32" title="guint32"><span class="returnvalue">guint32</span></a>
g_random_int (<em class="parameter"><code><span class="type">void</span></code></em>);</pre>
<p>Return a random <a class="link" href="glib-Basic-Types.html#guint32" title="guint32"><span class="type">guint32</span></a> equally distributed over the range
[0..2^32-1].</p>
<div class="refsect3">
<a name="g-random-int.returns"></a><h4>Returns</h4>
<p> a random number</p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-random-int-range"></a><h3>g_random_int_range ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gint32" title="gint32"><span class="returnvalue">gint32</span></a>
g_random_int_range (<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint32" title="gint32"><span class="type">gint32</span></a> begin</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint32" title="gint32"><span class="type">gint32</span></a> end</code></em>);</pre>
<p>Returns a random <a class="link" href="glib-Basic-Types.html#gint32" title="gint32"><span class="type">gint32</span></a> equally distributed over the range
[<em class="parameter"><code>begin</code></em>
..<em class="parameter"><code>end</code></em>
-1].</p>
<div class="refsect3">
<a name="g-random-int-range.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>begin</p></td>
<td class="parameter_description"><p>lower closed bound of the interval</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>end</p></td>
<td class="parameter_description"><p>upper open bound of the interval</p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-random-int-range.returns"></a><h4>Returns</h4>
<p> a random number</p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-random-double"></a><h3>g_random_double ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gdouble" title="gdouble"><span class="returnvalue">gdouble</span></a>
g_random_double (<em class="parameter"><code><span class="type">void</span></code></em>);</pre>
<p>Returns a random <a class="link" href="glib-Basic-Types.html#gdouble" title="gdouble"><span class="type">gdouble</span></a> equally distributed over the range [0..1).</p>
<div class="refsect3">
<a name="g-random-double.returns"></a><h4>Returns</h4>
<p> a random number</p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-random-double-range"></a><h3>g_random_double_range ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gdouble" title="gdouble"><span class="returnvalue">gdouble</span></a>
g_random_double_range (<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gdouble" title="gdouble"><span class="type">gdouble</span></a> begin</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gdouble" title="gdouble"><span class="type">gdouble</span></a> end</code></em>);</pre>
<p>Returns a random <a class="link" href="glib-Basic-Types.html#gdouble" title="gdouble"><span class="type">gdouble</span></a> equally distributed over the range
[<em class="parameter"><code>begin</code></em>
..<em class="parameter"><code>end</code></em>
).</p>
<div class="refsect3">
<a name="g-random-double-range.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>begin</p></td>
<td class="parameter_description"><p>lower closed bound of the interval</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>end</p></td>
<td class="parameter_description"><p>upper open bound of the interval</p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-random-double-range.returns"></a><h4>Returns</h4>
<p> a random number</p>
</div>
</div>
</div>
<div class="refsect1">
<a name="glib-Random-Numbers.other_details"></a><h2>Types and Values</h2>
<div class="refsect2">
<a name="GRand"></a><h3>GRand</h3>
<pre class="programlisting">typedef struct _GRand GRand;</pre>
<p>The GRand struct is an opaque data structure. It should only be
accessed through the g_rand_* functions.</p>
</div>
</div>
</div>
<div class="footer">
<hr>Generated by GTK-Doc V1.25.1</div>
</body>
</html>