|
Server : Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8e-fips-rhel5 DAV/2 PHP/5.2.17 System : Linux localhost 2.6.18-419.el5 #1 SMP Fri Feb 24 22:47:42 UTC 2017 x86_64 User : nobody ( 99) PHP Version : 5.2.17 Disable Function : NONE Directory : /proc/21585/root/usr/share/gtk-doc/html/glib/ |
Upload File : |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Random Numbers</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.69.1">
<link rel="start" href="index.html" title="GLib Reference Manual">
<link rel="up" href="glib-utilities.html" title="GLib Utilities">
<link rel="prev" href="glib-Date-and-Time-Functions.html" title="Date and Time Functions">
<link rel="next" href="glib-Hook-Functions.html" title="Hook Functions">
<meta name="generator" content="GTK-Doc V1.6 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
<link rel="chapter" href="glib.html" title="GLib Overview">
<link rel="chapter" href="glib-fundamentals.html" title="GLib Fundamentals">
<link rel="chapter" href="glib-core.html" title="GLib Core Application Support">
<link rel="chapter" href="glib-utilities.html" title="GLib Utilities">
<link rel="chapter" href="glib-data-types.html" title="GLib Data Types">
<link rel="chapter" href="tools.html" title="GLib Tools">
<link rel="index" href="ix01.html" title="Index">
<link rel="index" href="ix02.html" title="Index of deprecated symbols">
<link rel="index" href="ix03.html" title="Index of new symbols in 2.2">
<link rel="index" href="ix04.html" title="Index of new symbols in 2.4">
<link rel="index" href="ix05.html" title="Index of new symbols in 2.6">
<link rel="index" href="ix06.html" title="Index of new symbols in 2.8">
<link rel="index" href="ix07.html" title="Index of new symbols in 2.10">
<link rel="index" href="ix08.html" title="Index of new symbols in 2.12">
</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="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>
<tr><td colspan="5" class="shortcuts"><nobr><a href="#id3057459" class="shortcut">Top</a>
 | 
<a href="#id3057916" class="shortcut">Description</a></nobr></td></tr>
</table>
<div class="refentry" lang="en">
<a name="glib-Random-Numbers"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2>
<a name="id3057459"></a><span class="refentrytitle">Random Numbers</span>
</h2>
<p>Random Numbers — pseudo-random number generator.</p>
</td>
<td valign="top" align="right"></td>
</tr></table></div>
<div class="refsynopsisdiv">
<h2>Synopsis</h2>
<pre class="synopsis">
#include <glib.h>
<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="id3057916"></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
<code class="function">g_random_*</code> functions, which will create a globally
used <a href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a> and use the according <code class="function">g_rand_*</code> 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 <code class="function">g_rand_*</code>
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 <code class="function">g_rand*_range</code> functions will return high quality
equally distributed random numbers, whereas for example the
<code class="literal">(<a href="glib-Random-Numbers.html#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 <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
<code class="function">g_rand*<code class="function">_int_range()</code></code> 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="envar">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" lang="en">
<a name="id3058067"></a><h2>Details</h2>
<div class="refsect2" lang="en">
<a name="id3058077"></a><h3>
<a name="GRand"></a>GRand</h3>
<a class="indexterm" name="id3058090"></a><pre class="programlisting">typedef struct _GRand 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 <code class="function">g_rand_*</code> functions.
</p>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3058121"></a><h3>
<a name="g-rand-new-with-seed"></a>g_rand_new_with_seed ()</h3>
<a class="indexterm" name="id3058134"></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 <em class="parameter"><code>seed</code></em>.</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td>
<span class="term"><em class="parameter"><code>seed</code></em> :</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="id3058207"></a><h3>
<a name="g-rand-new-with-seed-array"></a>g_rand_new_with_seed_array ()</h3>
<a class="indexterm" name="id3058223"></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 <em class="parameter"><code>seed</code></em>.</p>
<p>
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td>
<span class="term"><em class="parameter"><code>seed</code></em> :</span></td>
<td> an array of seeds to initialize the random number generator.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>seed_length</code></em> :</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="id3058325"></a><h3>
<a name="g-rand-new"></a>g_rand_new ()</h3>
<a class="indexterm" name="id3058338"></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 <code class="filename">/dev/urandom</code> (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="id3058391"></a><h3>
<a name="g-rand-copy"></a>g_rand_copy ()</h3>
<a class="indexterm" name="id3058406"></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"><em class="parameter"><code>rand_</code></em> :</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="id3058495"></a><h3>
<a name="g-rand-free"></a>g_rand_free ()</h3>
<a class="indexterm" name="id3058508"></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"><em class="parameter"><code>rand_</code></em> :</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="id3058571"></a><h3>
<a name="g-rand-set-seed"></a>g_rand_set_seed ()</h3>
<a class="indexterm" name="id3058584"></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 <em class="parameter"><code>seed</code></em>.</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td>
<span class="term"><em class="parameter"><code>rand_</code></em> :</span></td>
<td> a <a href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a>.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>seed</code></em> :</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="id3058676"></a><h3>
<a name="g-rand-set-seed-array"></a>g_rand_set_seed_array ()</h3>
<a class="indexterm" name="id3058691"></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"><em class="parameter"><code>rand_</code></em> :</span></td>
<td> a <a href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a>.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>seed</code></em> :</span></td>
<td> array to initialize with
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>seed_length</code></em> :</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="id3058801"></a><h3>
<a name="g-rand-boolean"></a>g_rand_boolean()</h3>
<a class="indexterm" name="id3058813"></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 <em class="parameter"><code>rand_</code></em>. 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"><em class="parameter"><code>rand_</code></em> :</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="id3058888"></a><h3>
<a name="g-rand-int"></a>g_rand_int ()</h3>
<a class="indexterm" name="id3058900"></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 <em class="parameter"><code>rand_</code></em> 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"><em class="parameter"><code>rand_</code></em> :</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="id3058981"></a><h3>
<a name="g-rand-int-range"></a>g_rand_int_range ()</h3>
<a class="indexterm" name="id3058994"></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 <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="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td>
<span class="term"><em class="parameter"><code>rand_</code></em> :</span></td>
<td> a <a href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a>.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>begin</code></em> :</span></td>
<td> lower closed bound of the interval.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>end</code></em> :</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="id3059129"></a><h3>
<a name="g-rand-double"></a>g_rand_double ()</h3>
<a class="indexterm" name="id3059142"></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 <em class="parameter"><code>rand_</code></em> 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"><em class="parameter"><code>rand_</code></em> :</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="id3059222"></a><h3>
<a name="g-rand-double-range"></a>g_rand_double_range ()</h3>
<a class="indexterm" name="id3059236"></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 <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="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td>
<span class="term"><em class="parameter"><code>rand_</code></em> :</span></td>
<td> a <a href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a>.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>begin</code></em> :</span></td>
<td> lower closed bound of the interval.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>end</code></em> :</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="id3059370"></a><h3>
<a name="g-random-set-seed"></a>g_random_set_seed ()</h3>
<a class="indexterm" name="id3059384"></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 <code class="function">g_random_*</code> functions, to <em class="parameter"><code>seed</code></em>.</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody><tr>
<td>
<span class="term"><em class="parameter"><code>seed</code></em> :</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="id3059445"></a><h3>
<a name="g-random-boolean"></a>g_random_boolean()</h3>
<a class="indexterm" name="id3059458"></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="id3059505"></a><h3>
<a name="g-random-int"></a>g_random_int ()</h3>
<a class="indexterm" name="id3059518"></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="id3059564"></a><h3>
<a name="g-random-int-range"></a>g_random_int_range ()</h3>
<a class="indexterm" name="id3059578"></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
[<em class="parameter"><code>begin</code></em>..<em class="parameter"><code>end</code></em>-1].</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td>
<span class="term"><em class="parameter"><code>begin</code></em> :</span></td>
<td> lower closed bound of the interval.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>end</code></em> :</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="id3059677"></a><h3>
<a name="g-random-double"></a>g_random_double ()</h3>
<a class="indexterm" name="id3059690"></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="id3059736"></a><h3>
<a name="g-random-double-range"></a>g_random_double_range ()</h3>
<a class="indexterm" name="id3059750"></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 [<em class="parameter"><code>begin</code></em>..<em class="parameter"><code>end</code></em>).</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td>
<span class="term"><em class="parameter"><code>begin</code></em> :</span></td>
<td> lower closed bound of the interval.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>end</code></em> :</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>
</body>
</html>