3
<title>Random number generator initialization - GNU Scientific Library -- Reference Manual</title>
4
<meta http-equiv="Content-Type" content="text/html">
5
<meta name="description" content="GNU Scientific Library -- Reference Manual">
6
<meta name="generator" content="makeinfo 4.8">
7
<link title="Top" rel="start" href="index.html#Top">
8
<link rel="up" href="Random-Number-Generation.html#Random-Number-Generation" title="Random Number Generation">
9
<link rel="prev" href="The-Random-Number-Generator-Interface.html#The-Random-Number-Generator-Interface" title="The Random Number Generator Interface">
10
<link rel="next" href="Sampling-from-a-random-number-generator.html#Sampling-from-a-random-number-generator" title="Sampling from a random number generator">
11
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
13
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 The GSL Team.
15
Permission is granted to copy, distribute and/or modify this document
16
under the terms of the GNU Free Documentation License, Version 1.2 or
17
any later version published by the Free Software Foundation; with the
18
Invariant Sections being ``GNU General Public License'' and ``Free Software
19
Needs Free Documentation'', the Front-Cover text being ``A GNU Manual'',
20
and with the Back-Cover Text being (a) (see below). A copy of the
21
license is included in the section entitled ``GNU Free Documentation
24
(a) The Back-Cover Text is: ``You have freedom to copy and modify this
25
GNU Manual, like GNU software.''-->
26
<meta http-equiv="Content-Style-Type" content="text/css">
27
<style type="text/css"><!--
28
pre.display { font-family:inherit }
29
pre.format { font-family:inherit }
30
pre.smalldisplay { font-family:inherit; font-size:smaller }
31
pre.smallformat { font-family:inherit; font-size:smaller }
32
pre.smallexample { font-size:smaller }
33
pre.smalllisp { font-size:smaller }
34
span.sc { font-variant:small-caps }
35
span.roman { font-family:serif; font-weight:normal; }
36
span.sansserif { font-family:sans-serif; font-weight:normal; }
42
<a name="Random-number-generator-initialization"></a>
43
Next: <a rel="next" accesskey="n" href="Sampling-from-a-random-number-generator.html#Sampling-from-a-random-number-generator">Sampling from a random number generator</a>,
44
Previous: <a rel="previous" accesskey="p" href="The-Random-Number-Generator-Interface.html#The-Random-Number-Generator-Interface">The Random Number Generator Interface</a>,
45
Up: <a rel="up" accesskey="u" href="Random-Number-Generation.html#Random-Number-Generation">Random Number Generation</a>
49
<h3 class="section">17.3 Random number generator initialization</h3>
52
— Function: gsl_rng * <b>gsl_rng_alloc</b> (<var>const gsl_rng_type * T</var>)<var><a name="index-gsl_005frng_005falloc-1373"></a></var><br>
53
<blockquote><p>This function returns a pointer to a newly-created
54
instance of a random number generator of type <var>T</var>.
55
For example, the following code creates an instance of the Tausworthe
58
<pre class="example"> gsl_rng * r = gsl_rng_alloc (gsl_rng_taus);
60
<p>If there is insufficient memory to create the generator then the
61
function returns a null pointer and the error handler is invoked with an
62
error code of <code>GSL_ENOMEM</code>.
64
<p>The generator is automatically initialized with the default seed,
65
<code>gsl_rng_default_seed</code>. This is zero by default but can be changed
66
either directly or by using the environment variable <code>GSL_RNG_SEED</code>
67
(see <a href="Random-number-environment-variables.html#Random-number-environment-variables">Random number environment variables</a>).
69
<p>The details of the available generator types are
70
described later in this chapter.
71
</p></blockquote></div>
74
— Function: void <b>gsl_rng_set</b> (<var>const gsl_rng * r, unsigned long int s</var>)<var><a name="index-gsl_005frng_005fset-1374"></a></var><br>
75
<blockquote><p>This function initializes (or `seeds') the random number generator. If
76
the generator is seeded with the same value of <var>s</var> on two different
77
runs, the same stream of random numbers will be generated by successive
78
calls to the routines below. If different values of <var>s</var> are
79
supplied, then the generated streams of random numbers should be
80
completely different. If the seed <var>s</var> is zero then the standard seed
81
from the original implementation is used instead. For example, the
82
original Fortran source code for the <code>ranlux</code> generator used a seed
83
of 314159265, and so choosing <var>s</var> equal to zero reproduces this when
84
using <code>gsl_rng_ranlux</code>.
85
</p></blockquote></div>
88
— Function: void <b>gsl_rng_free</b> (<var>gsl_rng * r</var>)<var><a name="index-gsl_005frng_005ffree-1375"></a></var><br>
89
<blockquote><p>This function frees all the memory associated with the generator
91
</p></blockquote></div>