<?xml version="1.0"?>
<!DOCTYPE refentry PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN'
                      'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd' [
<!ENTITY % local.common.attrib "xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'">
<!ENTITY version SYSTEM "version.xml">
]>
<refentry id="glib-Random-Numbers">
<refmeta>
<refentrytitle role="top_of_page" id="glib-Random-Numbers.top_of_page">Random Numbers</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo>GLIB Library</refmiscinfo>
</refmeta>
<refnamediv>
<refname>Random Numbers</refname>
<refpurpose>pseudo-random number generator</refpurpose>
</refnamediv>

<refsect1 id="glib-Random-Numbers.functions" role="functions_proto">
<title role="functions_proto.title">Functions</title>
<informaltable pgwide="1" frame="none">
<tgroup cols="2">
<colspec colname="functions_return" colwidth="150px"/>
<colspec colname="functions_name"/>
<tbody>
<row><entry role="function_type"><link linkend="GRand"><returnvalue>GRand</returnvalue></link>&#160;*
</entry><entry role="function_name"><link linkend="g-rand-new-with-seed">g_rand_new_with_seed</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="GRand"><returnvalue>GRand</returnvalue></link>&#160;*
</entry><entry role="function_name"><link linkend="g-rand-new-with-seed-array">g_rand_new_with_seed_array</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="GRand"><returnvalue>GRand</returnvalue></link>&#160;*
</entry><entry role="function_name"><link linkend="g-rand-new">g_rand_new</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="GRand"><returnvalue>GRand</returnvalue></link>&#160;*
</entry><entry role="function_name"><link linkend="g-rand-copy">g_rand_copy</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="void"><returnvalue>void</returnvalue></link>
</entry><entry role="function_name"><link linkend="g-rand-free">g_rand_free</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="void"><returnvalue>void</returnvalue></link>
</entry><entry role="function_name"><link linkend="g-rand-set-seed">g_rand_set_seed</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="void"><returnvalue>void</returnvalue></link>
</entry><entry role="function_name"><link linkend="g-rand-set-seed-array">g_rand_set_seed_array</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="g-rand-boolean">g_rand_boolean</link><phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="guint32"><returnvalue>guint32</returnvalue></link>
</entry><entry role="function_name"><link linkend="g-rand-int">g_rand_int</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="gint32"><returnvalue>gint32</returnvalue></link>
</entry><entry role="function_name"><link linkend="g-rand-int-range">g_rand_int_range</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="gdouble"><returnvalue>gdouble</returnvalue></link>
</entry><entry role="function_name"><link linkend="g-rand-double">g_rand_double</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="gdouble"><returnvalue>gdouble</returnvalue></link>
</entry><entry role="function_name"><link linkend="g-rand-double-range">g_rand_double_range</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="void"><returnvalue>void</returnvalue></link>
</entry><entry role="function_name"><link linkend="g-random-set-seed">g_random_set_seed</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="g-random-boolean">g_random_boolean</link></entry></row>
<row><entry role="function_type"><link linkend="guint32"><returnvalue>guint32</returnvalue></link>
</entry><entry role="function_name"><link linkend="g-random-int">g_random_int</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="gint32"><returnvalue>gint32</returnvalue></link>
</entry><entry role="function_name"><link linkend="g-random-int-range">g_random_int_range</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="gdouble"><returnvalue>gdouble</returnvalue></link>
</entry><entry role="function_name"><link linkend="g-random-double">g_random_double</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="gdouble"><returnvalue>gdouble</returnvalue></link>
</entry><entry role="function_name"><link linkend="g-random-double-range">g_random_double_range</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>

</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 id="glib-Random-Numbers.other" role="other_proto">
<title role="other_proto.title">Types and Values</title>
<informaltable role="enum_members_table" pgwide="1" frame="none">
<tgroup cols="2">
<colspec colname="name" colwidth="150px"/>
<colspec colname="description"/>
<tbody>
<row><entry role="datatype_keyword"></entry><entry role="function_name"><link linkend="GRand">GRand</link></entry></row>

</tbody>
</tgroup>
</informaltable>
</refsect1>

<refsect1 id="glib-Random-Numbers.includes"><title>Includes</title><synopsis>#include &lt;gmodule.h&gt;
</synopsis></refsect1>

<refsect1 id="glib-Random-Numbers.description" role="desc">
<title role="desc.title">Description</title>
<para>The following functions allow you to use a portable, fast and good
pseudo-random number generator (PRNG).</para>
<para>Do not use this API for cryptographic purposes such as key
generation, nonces, salts or one-time pads.</para>
<para>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 <literal>/dev/random</literal> on UNIX, or <link linkend="CryptGenRandom"><function>CryptGenRandom()</function></link> on Windows.</para>
<para>GRand uses the Mersenne Twister PRNG, which was originally
developed by Makoto Matsumoto and Takuji Nishimura. Further
information can be found at
<ulink url="http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html">this page</ulink>.</para>
<para>If you just need a random number, you simply call the g_random_*
functions, which will create a globally used <link linkend="GRand"><type>GRand</type></link> and use the
according g_rand_* functions internally. Whenever you need a
stream of reproducible random numbers, you better create a
<link linkend="GRand"><type>GRand</type></link> yourself and use the g_rand_* functions directly, which
will also be slightly faster. Initializing a <link linkend="GRand"><type>GRand</type></link> 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.</para>
<para>The g_rand*_range functions will return high quality equally
distributed random numbers, whereas for example the
<literal>(<link linkend="g-random-int"><function>g_random_int()</function></link>%max)</literal> approach often
doesn't yield equally distributed numbers.</para>
<para>GLib changed the seeding algorithm for the pseudo-random number
generator Mersenne Twister, as used by <link linkend="GRand"><type>GRand</type></link>. 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.</para>
<para>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 <literal>G_RANDOM_VERSION</literal> 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.</para>

</refsect1>
<refsect1 id="glib-Random-Numbers.functions_details" role="details">
<title role="details.title">Functions</title>
<refsect2 id="g-rand-new-with-seed" role="function">
<title>g_rand_new_with_seed&#160;()</title>
<indexterm zone="g-rand-new-with-seed"><primary sortas="rand_new_with_seed">g_rand_new_with_seed</primary></indexterm>
<programlisting language="C"><link linkend="GRand"><returnvalue>GRand</returnvalue></link>&#160;*
g_rand_new_with_seed (<parameter><link linkend="guint32"><type>guint32</type></link> seed</parameter>);</programlisting>
<para>Creates a new random number generator initialized with <parameter>seed</parameter>
.</para>
<refsect3 id="g-rand-new-with-seed.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>seed</para></entry>
<entry role="parameter_description"><para>a value to initialize the random number generator</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-rand-new-with-seed.returns" role="returns">
<title>Returns</title>
<para> the new <link linkend="GRand"><type>GRand</type></link></para>
</refsect3></refsect2>
<refsect2 id="g-rand-new-with-seed-array" role="function" condition="since:2.4">
<title>g_rand_new_with_seed_array&#160;()</title>
<indexterm zone="g-rand-new-with-seed-array" role="2.4"><primary sortas="rand_new_with_seed_array">g_rand_new_with_seed_array</primary></indexterm>
<programlisting language="C"><link linkend="GRand"><returnvalue>GRand</returnvalue></link>&#160;*
g_rand_new_with_seed_array (<parameter>const <link linkend="guint32"><type>guint32</type></link> *seed</parameter>,
                            <parameter><link linkend="guint"><type>guint</type></link> seed_length</parameter>);</programlisting>
<para>Creates a new random number generator initialized with <parameter>seed</parameter>
.</para>
<refsect3 id="g-rand-new-with-seed-array.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>seed</para></entry>
<entry role="parameter_description"><para>an array of seeds to initialize the random number generator</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>seed_length</para></entry>
<entry role="parameter_description"><para>an array of seeds to initialize the random number
generator</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-rand-new-with-seed-array.returns" role="returns">
<title>Returns</title>
<para> the new <link linkend="GRand"><type>GRand</type></link></para>
</refsect3><para role="since">Since: <link linkend="api-index-2.4">2.4</link></para></refsect2>
<refsect2 id="g-rand-new" role="function">
<title>g_rand_new&#160;()</title>
<indexterm zone="g-rand-new"><primary sortas="rand_new">g_rand_new</primary></indexterm>
<programlisting language="C"><link linkend="GRand"><returnvalue>GRand</returnvalue></link>&#160;*
g_rand_new (<parameter><type>void</type></parameter>);</programlisting>
<para>Creates a new random number generator initialized with a seed taken
either from <literal>/dev/urandom</literal> (if existing) or from the current time
(as a fallback).</para>
<para>On Windows, the seed is taken from <link linkend="rand-s"><function>rand_s()</function></link>.</para>
<refsect3 id="g-rand-new.returns" role="returns">
<title>Returns</title>
<para> the new <link linkend="GRand"><type>GRand</type></link></para>
</refsect3></refsect2>
<refsect2 id="g-rand-copy" role="function" condition="since:2.4">
<title>g_rand_copy&#160;()</title>
<indexterm zone="g-rand-copy" role="2.4"><primary sortas="rand_copy">g_rand_copy</primary></indexterm>
<programlisting language="C"><link linkend="GRand"><returnvalue>GRand</returnvalue></link>&#160;*
g_rand_copy (<parameter><link linkend="GRand"><type>GRand</type></link> *rand_</parameter>);</programlisting>
<para>Copies a <link linkend="GRand"><type>GRand</type></link> 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.</para>
<refsect3 id="g-rand-copy.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>rand_</para></entry>
<entry role="parameter_description"><para>a <link linkend="GRand"><type>GRand</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-rand-copy.returns" role="returns">
<title>Returns</title>
<para> the new <link linkend="GRand"><type>GRand</type></link></para>
</refsect3><para role="since">Since: <link linkend="api-index-2.4">2.4</link></para></refsect2>
<refsect2 id="g-rand-free" role="function">
<title>g_rand_free&#160;()</title>
<indexterm zone="g-rand-free"><primary sortas="rand_free">g_rand_free</primary></indexterm>
<programlisting language="C"><link linkend="void"><returnvalue>void</returnvalue></link>
g_rand_free (<parameter><link linkend="GRand"><type>GRand</type></link> *rand_</parameter>);</programlisting>
<para>Frees the memory allocated for the <link linkend="GRand"><type>GRand</type></link>.</para>
<refsect3 id="g-rand-free.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>rand_</para></entry>
<entry role="parameter_description"><para>a <link linkend="GRand"><type>GRand</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3></refsect2>
<refsect2 id="g-rand-set-seed" role="function">
<title>g_rand_set_seed&#160;()</title>
<indexterm zone="g-rand-set-seed"><primary sortas="rand_set_seed">g_rand_set_seed</primary></indexterm>
<programlisting language="C"><link linkend="void"><returnvalue>void</returnvalue></link>
g_rand_set_seed (<parameter><link linkend="GRand"><type>GRand</type></link> *rand_</parameter>,
                 <parameter><link linkend="guint32"><type>guint32</type></link> seed</parameter>);</programlisting>
<para>Sets the seed for the random number generator <link linkend="GRand"><type>GRand</type></link> to <parameter>seed</parameter>
.</para>
<refsect3 id="g-rand-set-seed.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>rand_</para></entry>
<entry role="parameter_description"><para>a <link linkend="GRand"><type>GRand</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>seed</para></entry>
<entry role="parameter_description"><para>a value to reinitialize the random number generator</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3></refsect2>
<refsect2 id="g-rand-set-seed-array" role="function" condition="since:2.4">
<title>g_rand_set_seed_array&#160;()</title>
<indexterm zone="g-rand-set-seed-array" role="2.4"><primary sortas="rand_set_seed_array">g_rand_set_seed_array</primary></indexterm>
<programlisting language="C"><link linkend="void"><returnvalue>void</returnvalue></link>
g_rand_set_seed_array (<parameter><link linkend="GRand"><type>GRand</type></link> *rand_</parameter>,
                       <parameter>const <link linkend="guint32"><type>guint32</type></link> *seed</parameter>,
                       <parameter><link linkend="guint"><type>guint</type></link> seed_length</parameter>);</programlisting>
<para>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.</para>
<refsect3 id="g-rand-set-seed-array.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>rand_</para></entry>
<entry role="parameter_description"><para>a <link linkend="GRand"><type>GRand</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>seed</para></entry>
<entry role="parameter_description"><para>array to initialize with</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>seed_length</para></entry>
<entry role="parameter_description"><para>length of array</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><para role="since">Since: <link linkend="api-index-2.4">2.4</link></para></refsect2>
<refsect2 id="g-rand-boolean" role="macro">
<title>g_rand_boolean()</title>
<indexterm zone="g-rand-boolean"><primary sortas="rand_boolean">g_rand_boolean</primary></indexterm>
<programlisting language="C">#define             g_rand_boolean(rand_)</programlisting>
<para>Returns a random <link linkend="gboolean"><type>gboolean</type></link> from <parameter>rand_</parameter>
.
This corresponds to a unbiased coin toss.</para>
<refsect3 id="g-rand-boolean.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>rand_</para></entry>
<entry role="parameter_description"><para>a <link linkend="GRand"><type>GRand</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-rand-boolean.returns" role="returns">
<title>Returns</title>
<para> a random <link linkend="gboolean"><type>gboolean</type></link></para>
</refsect3></refsect2>
<refsect2 id="g-rand-int" role="function">
<title>g_rand_int&#160;()</title>
<indexterm zone="g-rand-int"><primary sortas="rand_int">g_rand_int</primary></indexterm>
<programlisting language="C"><link linkend="guint32"><returnvalue>guint32</returnvalue></link>
g_rand_int (<parameter><link linkend="GRand"><type>GRand</type></link> *rand_</parameter>);</programlisting>
<para>Returns the next random <link linkend="guint32"><type>guint32</type></link> from <parameter>rand_</parameter>
 equally distributed over
the range [0..2^32-1].</para>
<refsect3 id="g-rand-int.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>rand_</para></entry>
<entry role="parameter_description"><para>a <link linkend="GRand"><type>GRand</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-rand-int.returns" role="returns">
<title>Returns</title>
<para> a random number</para>
</refsect3></refsect2>
<refsect2 id="g-rand-int-range" role="function">
<title>g_rand_int_range&#160;()</title>
<indexterm zone="g-rand-int-range"><primary sortas="rand_int_range">g_rand_int_range</primary></indexterm>
<programlisting language="C"><link linkend="gint32"><returnvalue>gint32</returnvalue></link>
g_rand_int_range (<parameter><link linkend="GRand"><type>GRand</type></link> *rand_</parameter>,
                  <parameter><link linkend="gint32"><type>gint32</type></link> begin</parameter>,
                  <parameter><link linkend="gint32"><type>gint32</type></link> end</parameter>);</programlisting>
<para>Returns the next random <link linkend="gint32"><type>gint32</type></link> from <parameter>rand_</parameter>
 equally distributed over
the range [<parameter>begin</parameter>
..<parameter>end</parameter>
-1].</para>
<refsect3 id="g-rand-int-range.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>rand_</para></entry>
<entry role="parameter_description"><para>a <link linkend="GRand"><type>GRand</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>begin</para></entry>
<entry role="parameter_description"><para>lower closed bound of the interval</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>end</para></entry>
<entry role="parameter_description"><para>upper open bound of the interval</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-rand-int-range.returns" role="returns">
<title>Returns</title>
<para> a random number</para>
</refsect3></refsect2>
<refsect2 id="g-rand-double" role="function">
<title>g_rand_double&#160;()</title>
<indexterm zone="g-rand-double"><primary sortas="rand_double">g_rand_double</primary></indexterm>
<programlisting language="C"><link linkend="gdouble"><returnvalue>gdouble</returnvalue></link>
g_rand_double (<parameter><link linkend="GRand"><type>GRand</type></link> *rand_</parameter>);</programlisting>
<para>Returns the next random <link linkend="gdouble"><type>gdouble</type></link> from <parameter>rand_</parameter>
 equally distributed over
the range [0..1).</para>
<refsect3 id="g-rand-double.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>rand_</para></entry>
<entry role="parameter_description"><para>a <link linkend="GRand"><type>GRand</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-rand-double.returns" role="returns">
<title>Returns</title>
<para> a random number</para>
</refsect3></refsect2>
<refsect2 id="g-rand-double-range" role="function">
<title>g_rand_double_range&#160;()</title>
<indexterm zone="g-rand-double-range"><primary sortas="rand_double_range">g_rand_double_range</primary></indexterm>
<programlisting language="C"><link linkend="gdouble"><returnvalue>gdouble</returnvalue></link>
g_rand_double_range (<parameter><link linkend="GRand"><type>GRand</type></link> *rand_</parameter>,
                     <parameter><link linkend="gdouble"><type>gdouble</type></link> begin</parameter>,
                     <parameter><link linkend="gdouble"><type>gdouble</type></link> end</parameter>);</programlisting>
<para>Returns the next random <link linkend="gdouble"><type>gdouble</type></link> from <parameter>rand_</parameter>
 equally distributed over
the range [<parameter>begin</parameter>
..<parameter>end</parameter>
).</para>
<refsect3 id="g-rand-double-range.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>rand_</para></entry>
<entry role="parameter_description"><para>a <link linkend="GRand"><type>GRand</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>begin</para></entry>
<entry role="parameter_description"><para>lower closed bound of the interval</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>end</para></entry>
<entry role="parameter_description"><para>upper open bound of the interval</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-rand-double-range.returns" role="returns">
<title>Returns</title>
<para> a random number</para>
</refsect3></refsect2>
<refsect2 id="g-random-set-seed" role="function">
<title>g_random_set_seed&#160;()</title>
<indexterm zone="g-random-set-seed"><primary sortas="random_set_seed">g_random_set_seed</primary></indexterm>
<programlisting language="C"><link linkend="void"><returnvalue>void</returnvalue></link>
g_random_set_seed (<parameter><link linkend="guint32"><type>guint32</type></link> seed</parameter>);</programlisting>
<para>Sets the seed for the global random number generator, which is used
by the g_random_* functions, to <parameter>seed</parameter>
.</para>
<refsect3 id="g-random-set-seed.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>seed</para></entry>
<entry role="parameter_description"><para>a value to reinitialize the global random number generator</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3></refsect2>
<refsect2 id="g-random-boolean" role="macro">
<title>g_random_boolean</title>
<indexterm zone="g-random-boolean"><primary sortas="random_boolean">g_random_boolean</primary></indexterm>
<programlisting language="C">#define             g_random_boolean()</programlisting>
<para>Returns a random <link linkend="gboolean"><type>gboolean</type></link>.
This corresponds to a unbiased coin toss.</para>
<refsect3 id="g-random-boolean.returns" role="returns">
<title>Returns</title>
<para> a random <link linkend="gboolean"><type>gboolean</type></link></para>
</refsect3></refsect2>
<refsect2 id="g-random-int" role="function">
<title>g_random_int&#160;()</title>
<indexterm zone="g-random-int"><primary sortas="random_int">g_random_int</primary></indexterm>
<programlisting language="C"><link linkend="guint32"><returnvalue>guint32</returnvalue></link>
g_random_int (<parameter><type>void</type></parameter>);</programlisting>
<para>Return a random <link linkend="guint32"><type>guint32</type></link> equally distributed over the range
[0..2^32-1].</para>
<refsect3 id="g-random-int.returns" role="returns">
<title>Returns</title>
<para> a random number</para>
</refsect3></refsect2>
<refsect2 id="g-random-int-range" role="function">
<title>g_random_int_range&#160;()</title>
<indexterm zone="g-random-int-range"><primary sortas="random_int_range">g_random_int_range</primary></indexterm>
<programlisting language="C"><link linkend="gint32"><returnvalue>gint32</returnvalue></link>
g_random_int_range (<parameter><link linkend="gint32"><type>gint32</type></link> begin</parameter>,
                    <parameter><link linkend="gint32"><type>gint32</type></link> end</parameter>);</programlisting>
<para>Returns a random <link linkend="gint32"><type>gint32</type></link> equally distributed over the range
[<parameter>begin</parameter>
..<parameter>end</parameter>
-1].</para>
<refsect3 id="g-random-int-range.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>begin</para></entry>
<entry role="parameter_description"><para>lower closed bound of the interval</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>end</para></entry>
<entry role="parameter_description"><para>upper open bound of the interval</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-random-int-range.returns" role="returns">
<title>Returns</title>
<para> a random number</para>
</refsect3></refsect2>
<refsect2 id="g-random-double" role="function">
<title>g_random_double&#160;()</title>
<indexterm zone="g-random-double"><primary sortas="random_double">g_random_double</primary></indexterm>
<programlisting language="C"><link linkend="gdouble"><returnvalue>gdouble</returnvalue></link>
g_random_double (<parameter><type>void</type></parameter>);</programlisting>
<para>Returns a random <link linkend="gdouble"><type>gdouble</type></link> equally distributed over the range [0..1).</para>
<refsect3 id="g-random-double.returns" role="returns">
<title>Returns</title>
<para> a random number</para>
</refsect3></refsect2>
<refsect2 id="g-random-double-range" role="function">
<title>g_random_double_range&#160;()</title>
<indexterm zone="g-random-double-range"><primary sortas="random_double_range">g_random_double_range</primary></indexterm>
<programlisting language="C"><link linkend="gdouble"><returnvalue>gdouble</returnvalue></link>
g_random_double_range (<parameter><link linkend="gdouble"><type>gdouble</type></link> begin</parameter>,
                       <parameter><link linkend="gdouble"><type>gdouble</type></link> end</parameter>);</programlisting>
<para>Returns a random <link linkend="gdouble"><type>gdouble</type></link> equally distributed over the range
[<parameter>begin</parameter>
..<parameter>end</parameter>
).</para>
<refsect3 id="g-random-double-range.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>begin</para></entry>
<entry role="parameter_description"><para>lower closed bound of the interval</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>end</para></entry>
<entry role="parameter_description"><para>upper open bound of the interval</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-random-double-range.returns" role="returns">
<title>Returns</title>
<para> a random number</para>
</refsect3></refsect2>

</refsect1>
<refsect1 id="glib-Random-Numbers.other_details" role="details">
<title role="details.title">Types and Values</title>
<refsect2 id="GRand" role="struct">
<title>GRand</title>
<indexterm zone="GRand"><primary sortas="Rand">GRand</primary></indexterm>
<programlisting language="C">typedef struct _GRand GRand;</programlisting>
<para>The GRand struct is an opaque data structure. It should only be
accessed through the g_rand_* functions.</para>
</refsect2>

</refsect1>

</refentry>
