Files
Abdelrahman Said a11edf0c53 Add graph references
2026-06-28 13:49:01 +01:00

1527 lines
57 KiB
HTML
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Chapter 8. Random numbers</title>
<meta name="generator" content="DocBook XSL Stylesheets Vsnapshot">
<link rel="home" href="index.html" title="igraph Reference Manual">
<link rel="up" href="index.html" title="igraph Reference Manual">
<link rel="prev" href="igraph-Data-structures.html" title="Chapter 7. Data structure library: vector, matrix, other data types">
<link rel="next" href="igraph-Iterators.html" title="Chapter 9. Vertex and edge selectors and sequences, iterators">
<script type="text/javascript" src="toggle.js"></script><link rel="stylesheet" href="style.css" type="text/css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" type="text/css">
<link rel="chapter" href="igraph-Introduction.html" title="Chapter 1. Introduction">
<link rel="chapter" href="igraph-Installation.html" title="Chapter 2. Installation">
<link rel="chapter" href="igraph-Tutorial.html" title="Chapter 3. Tutorial">
<link rel="chapter" href="igraph-Basic.html" title="Chapter 4. Basic data types and interface">
<link rel="chapter" href="igraph-Error.html" title="Chapter 5. Error handling">
<link rel="chapter" href="igraph-Memory.html" title="Chapter 6. Memory (de)allocation">
<link rel="chapter" href="igraph-Data-structures.html" title="Chapter 7. Data structure library: vector, matrix, other data types">
<link rel="chapter" href="igraph-Random.html" title="Chapter 8. Random numbers">
<link rel="chapter" href="igraph-Iterators.html" title="Chapter 9. Vertex and edge selectors and sequences, iterators">
<link rel="chapter" href="igraph-Attributes.html" title="Chapter 10. Graph, vertex and edge attributes">
<link rel="chapter" href="igraph-Generators.html" title="Chapter 11. Deterministic graph generators">
<link rel="chapter" href="igraph-Games.html" title='Chapter 12. Stochastic graph generators ("games")'>
<link rel="chapter" href="igraph-Bipartite.html" title="Chapter 13. Bipartite, i.e. two-mode graphs">
<link rel="chapter" href="igraph-Spatial.html" title="Chapter 14. Spatial graphs">
<link rel="chapter" href="igraph-Operators.html" title="Chapter 15. Graph operators">
<link rel="chapter" href="igraph-Visitors.html" title="Chapter 16. Graph visitors">
<link rel="chapter" href="igraph-Structural.html" title="Chapter 17. Structural properties of graphs">
<link rel="chapter" href="igraph-Cycles.html" title="Chapter 18. Graph cycles">
<link rel="chapter" href="igraph-Cliques.html" title="Chapter 19. Cliques and independent vertex sets">
<link rel="chapter" href="igraph-Motifs.html" title="Chapter 20. Graph motifs, dyad census and triad census">
<link rel="chapter" href="igraph-Isomorphism.html" title="Chapter 21. Graph isomorphism">
<link rel="chapter" href="igraph-Coloring.html" title="Chapter 22. Graph coloring">
<link rel="chapter" href="igraph-Flows.html" title="Chapter 23. Maximum flows, minimum cuts and related measures">
<link rel="chapter" href="igraph-Separators.html" title="Chapter 24. Vertex separators">
<link rel="chapter" href="igraph-Community.html" title="Chapter 25. Detecting community structure">
<link rel="chapter" href="igraph-Graphlets.html" title="Chapter 26. Graphlets">
<link rel="chapter" href="igraph-HRG.html" title="Chapter 27. Hierarchical random graphs">
<link rel="chapter" href="igraph-Embedding.html" title="Chapter 28. Embedding of graphs">
<link rel="chapter" href="igraph-Layout.html" title="Chapter 29. Generating layouts for graph drawing">
<link rel="chapter" href="igraph-Processes.html" title="Chapter 30. Processes on graphs">
<link rel="chapter" href="igraph-Foreign.html" title="Chapter 31. Reading and writing graphs from and to files">
<link rel="chapter" href="igraph-Linalg.html" title="Chapter 32. Using BLAS, LAPACK and ARPACK for igraph matrices and graphs">
<link rel="chapter" href="igraph-Nongraph.html" title="Chapter 33. Non-graph related functions">
<link rel="chapter" href="igraph-Advanced.html" title="Chapter 34. Advanced igraph programming">
<link rel="chapter" href="igraph-Glossary.html" title="Chapter 35. Glossary">
<link rel="chapter" href="igraph-Licenses.html" title="Chapter 36. Licenses for igraph and this manual">
<link rel="index" href="ix01.html" title="Index">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navigation-header mb-4" width="100%" summary="Navigation header"><div class="btn-group">
<a accesskey="p" class="btn btn-light" href="igraph-Data-structures.html"><i class="fa fa-chevron-left"></i>
Previous
</a><a accesskey="h" class="btn btn-light" href="index.html"><i class="fa fa-home"></i>
Home
</a><a accesskey="n" class="btn btn-light" href="igraph-Iterators.html"><i class="fa fa-chevron-right"></i>
Next
</a>
</div></div>
<div class="chapter">
<div class="titlepage"><div><div><h1 class="title">
<a name="igraph-Random"></a>Chapter 8. Random numbers</h1></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="igraph-Random.html#about-random-numbers-in-igraph">1. About random numbers in igraph</a></span></dt>
<dt><span class="section"><a href="igraph-Random.html#default-random-number-generator">2. The default random number generator</a></span></dt>
<dt><span class="section"><a href="igraph-Random.html#creating-random-number-generators">3. Creating random number generators</a></span></dt>
<dt><span class="section"><a href="igraph-Random.html#generating-random-numbers">4. Generating random numbers</a></span></dt>
<dt><span class="section"><a href="igraph-Random.html#supported-random-number-generators">5. Supported random number generators</a></span></dt>
<dt><span class="section"><a href="igraph-Random.html#random-use-cases">6. Use cases</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="about-random-numbers-in-igraph"></a>1. About random numbers in igraph</h2></div></div></div>
<p>
Some algorithms in igraph, such as sampling from random graph models,
require random number generators (RNGs). igraph includes a flexible
RNG framework that allows hooking up arbitrary random number generators,
and comes with several ready-to-use generators. This framework is used
in igraph's high-level interfaces to integrate with the host language's
own RNG.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="default-random-number-generator"></a>2. The default random number generator</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="igraph-Random.html#igraph_rng_default">2.1. <code class="function">igraph_rng_default</code> — Query the default random number generator.</a></span></dt>
<dt><span class="section"><a href="igraph-Random.html#igraph_rng_set_default">2.2. <code class="function">igraph_rng_set_default</code> — Set the default igraph random number generator.</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="igraph_rng_default"></a>2.1. <code class="function">igraph_rng_default</code> — Query the default random number generator.</h3></div></div></div>
<a class="indexterm" name="id-1.9.3.2.2"></a><p>
</p>
<div class="informalexample"><pre class="programlisting">
igraph_rng_t *igraph_rng_default(void);
</pre></div>
<p>
</p>
<p>
</p>
<p><b>Returns: </b></p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
<td><p>
A pointer to the default random number generator.
</p></td>
</tr></tbody>
</table></div>
<p>
</p>
<p><b>See also: </b></p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
<td><p>
<a class="link" href="igraph-Random.html#igraph_rng_set_default" title="2.2. igraph_rng_set_default — Set the default igraph random number generator."><code class="function">igraph_rng_set_default()</code></a>
</p></td>
</tr></tbody>
</table></div>
<p>
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="igraph_rng_set_default"></a>2.2. <code class="function">igraph_rng_set_default</code> — Set the default igraph random number generator.</h3></div></div></div>
<a class="indexterm" name="id-1.9.3.3.2"></a><p>
</p>
<div class="informalexample"><pre class="programlisting">
igraph_rng_t *igraph_rng_set_default(igraph_rng_t *rng);
</pre></div>
<p>
</p>
<p>
This function updates the default RNG used by igraph to be the one
pointed to by <em class="parameter"><code>rng</code></em>, and returns a pointer to the previous default
RNG. Future calls to <a class="link" href="igraph-Random.html#igraph_rng_default" title="2.1. igraph_rng_default — Query the default random number generator."><code class="function">igraph_rng_default()</code></a> will return the same
pointer as <em class="parameter"><code>rng</code></em>. The RNG pointed to by <em class="parameter"><code>rng</code></em> must not be destroyed
for as long as it is used as the default.
</p>
<p><b>Arguments: </b>
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code>rng</code></em>:</span></p></td>
<td><p>
The random number generator to use as default from now
on. Calling <a class="link" href="igraph-Random.html#igraph_rng_destroy" title="3.2. igraph_rng_destroy — Deallocates memory associated with a random number generator."><code class="function">igraph_rng_destroy()</code></a> on it, while it is still
being used as the default will result in crashes and/or
unpredictable results.
</p></td>
</tr></tbody>
</table></div>
<p>
</p>
<p><b>Returns: </b></p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
<td><p>
Pointer the previous default RNG.
</p></td>
</tr></tbody>
</table></div>
<p>
Time complexity: O(1).
</p>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="creating-random-number-generators"></a>3. Creating random number generators</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="igraph-Random.html#igraph_rng_init">3.1. <code class="function">igraph_rng_init</code> — Initializes a random number generator.</a></span></dt>
<dt><span class="section"><a href="igraph-Random.html#igraph_rng_destroy">3.2. <code class="function">igraph_rng_destroy</code> — Deallocates memory associated with a random number generator.</a></span></dt>
<dt><span class="section"><a href="igraph-Random.html#igraph_rng_seed">3.3. <code class="function">igraph_rng_seed</code> — Seeds a random number generator.</a></span></dt>
<dt><span class="section"><a href="igraph-Random.html#igraph_rng_bits">3.4. <code class="function">igraph_rng_bits</code> — The number of random bits that a random number generator can produces in a single round.</a></span></dt>
<dt><span class="section"><a href="igraph-Random.html#igraph_rng_max">3.5. <code class="function">igraph_rng_max</code> — The maximum possible integer for a random number generator.</a></span></dt>
<dt><span class="section"><a href="igraph-Random.html#igraph_rng_name">3.6. <code class="function">igraph_rng_name</code> — The type of a random number generator.</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="igraph_rng_init"></a>3.1. <code class="function">igraph_rng_init</code> — Initializes a random number generator.</h3></div></div></div>
<a class="indexterm" name="id-1.9.4.2.2"></a><p>
</p>
<div class="informalexample"><pre class="programlisting">
igraph_error_t igraph_rng_init(igraph_rng_t *rng, const igraph_rng_type_t *type);
</pre></div>
<p>
</p>
<p>
This function allocates memory for a random number generator, with
the given type, and sets its seed to the default.
</p>
<p><b>Arguments: </b>
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>rng</code></em>:</span></p></td>
<td><p>
Pointer to an uninitialized RNG.
</p></td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>type</code></em>:</span></p></td>
<td><p>
The type of the RNG, such as <a class="link" href="igraph-Random.html#igraph_rngtype_mt19937" title="5.1. igraph_rngtype_mt19937 — The MT19937 random number generator."><code class="function">igraph_rngtype_mt19937</code></a>,
<a class="link" href="igraph-Random.html#igraph_rngtype_glibc2" title="5.2. igraph_rngtype_glibc2 — The random number generator introduced in GNU libc 2."><code class="function">igraph_rngtype_glibc2</code></a>, <a class="link" href="igraph-Random.html#igraph_rngtype_pcg32" title="5.3. igraph_rngtype_pcg32 — The PCG random number generator (32-bit version)."><code class="function">igraph_rngtype_pcg32</code></a> or
<a class="link" href="igraph-Random.html#igraph_rngtype_pcg64" title="5.4. igraph_rngtype_pcg64 — The PCG random number generator (64-bit version)."><code class="function">igraph_rngtype_pcg64</code></a>.
</p></td>
</tr>
</tbody>
</table></div>
<p>
</p>
<p><b>Returns: </b></p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
<td><p>
Error code.
</p></td>
</tr></tbody>
</table></div>
<p>
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="igraph_rng_destroy"></a>3.2. <code class="function">igraph_rng_destroy</code> — Deallocates memory associated with a random number generator.</h3></div></div></div>
<a class="indexterm" name="id-1.9.4.3.2"></a><p>
</p>
<div class="informalexample"><pre class="programlisting">
void igraph_rng_destroy(igraph_rng_t *rng);
</pre></div>
<p>
</p>
<p>
</p>
<p><b>Arguments: </b>
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code>rng</code></em>:</span></p></td>
<td><p>
The RNG to destroy. Do not destroy an RNG that is used
as the default igraph RNG.</p></td>
</tr></tbody>
</table></div>
<p>
Time complexity: O(1).
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="igraph_rng_seed"></a>3.3. <code class="function">igraph_rng_seed</code> — Seeds a random number generator.</h3></div></div></div>
<a class="indexterm" name="id-1.9.4.4.2"></a><p>
</p>
<div class="informalexample"><pre class="programlisting">
igraph_error_t igraph_rng_seed(igraph_rng_t *rng, igraph_uint_t seed);
</pre></div>
<p>
</p>
<p>
</p>
<p><b>Arguments: </b>
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>rng</code></em>:</span></p></td>
<td><p>
The RNG.
</p></td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>seed</code></em>:</span></p></td>
<td><p>
The new seed.
</p></td>
</tr>
</tbody>
</table></div>
<p>
</p>
<p><b>Returns: </b></p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
<td><p>
Error code.
</p></td>
</tr></tbody>
</table></div>
<p>
Time complexity: usually O(1), but may depend on the type of the
RNG.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="igraph_rng_bits"></a>3.4. <code class="function">igraph_rng_bits</code> — The number of random bits that a random number generator can produces in a single round.</h3></div></div></div>
<a class="indexterm" name="id-1.9.4.5.2"></a><p>
</p>
<div class="informalexample"><pre class="programlisting">
igraph_int_t igraph_rng_bits(const igraph_rng_t* rng);
</pre></div>
<p>
</p>
<p>
</p>
<p><b>Arguments: </b>
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code>rng</code></em>:</span></p></td>
<td><p>
The RNG.
</p></td>
</tr></tbody>
</table></div>
<p>
</p>
<p><b>Returns: </b></p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
<td><p>
The number of random bits that can be generated in a single round
with the RNG.
</p></td>
</tr></tbody>
</table></div>
<p>
Time complexity: O(1).
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="igraph_rng_max"></a>3.5. <code class="function">igraph_rng_max</code> — The maximum possible integer for a random number generator.</h3></div></div></div>
<a class="indexterm" name="id-1.9.4.6.2"></a><p>
</p>
<div class="informalexample"><pre class="programlisting">
igraph_uint_t igraph_rng_max(const igraph_rng_t *rng);
</pre></div>
<p>
</p>
<p>
Note that this number is only for informational purposes; it returns the
maximum possible integer that can be generated with the RNG with a single
call to its internals. It is derived directly from the number of random
<span class="emphasis"><em>bits</em></span> that the RNG can generate in a single round. When this is smaller
than what would be needed by other RNG functions like <a class="link" href="igraph-Random.html#igraph_rng_get_integer" title="4.2. igraph_rng_get_integer — Generate an integer random number from an interval."><code class="function">igraph_rng_get_integer()</code></a>,
igraph will call the RNG multiple times to generate more random bits.
</p>
<p><b>Arguments: </b>
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code>rng</code></em>:</span></p></td>
<td><p>
The RNG.
</p></td>
</tr></tbody>
</table></div>
<p>
</p>
<p><b>Returns: </b></p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
<td><p>
The largest possible integer that can be generated in a single round
with the RNG.
</p></td>
</tr></tbody>
</table></div>
<p>
Time complexity: O(1).
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="igraph_rng_name"></a>3.6. <code class="function">igraph_rng_name</code> — The type of a random number generator.</h3></div></div></div>
<a class="indexterm" name="id-1.9.4.7.2"></a><p>
</p>
<div class="informalexample"><pre class="programlisting">
const char *igraph_rng_name(const igraph_rng_t *rng);
</pre></div>
<p>
</p>
<p>
</p>
<p><b>Arguments: </b>
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code>rng</code></em>:</span></p></td>
<td><p>
The RNG.
</p></td>
</tr></tbody>
</table></div>
<p>
</p>
<p><b>Returns: </b></p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
<td><p>
The name of the type of the generator. Do not deallocate or
change the returned string.
</p></td>
</tr></tbody>
</table></div>
<p>
Time complexity: O(1).
</p>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="generating-random-numbers"></a>4. Generating random numbers</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="igraph-Random.html#igraph_rng_get_bool">4.1. <code class="function">igraph_rng_get_bool</code> — Generate a random boolean.</a></span></dt>
<dt><span class="section"><a href="igraph-Random.html#igraph_rng_get_integer">4.2. <code class="function">igraph_rng_get_integer</code> — Generate an integer random number from an interval.</a></span></dt>
<dt><span class="section"><a href="igraph-Random.html#igraph_rng_get_unif01">4.3. <code class="function">igraph_rng_get_unif01</code> — Samples uniformly from the unit interval.</a></span></dt>
<dt><span class="section"><a href="igraph-Random.html#igraph_rng_get_unif">4.4. <code class="function">igraph_rng_get_unif</code> — Samples real numbers from a given interval.</a></span></dt>
<dt><span class="section"><a href="igraph-Random.html#igraph_rng_get_normal">4.5. <code class="function">igraph_rng_get_normal</code> — Samples from a normal distribution.</a></span></dt>
<dt><span class="section"><a href="igraph-Random.html#igraph_rng_get_exp">4.6. <code class="function">igraph_rng_get_exp</code> — Samples from an exponential distribution.</a></span></dt>
<dt><span class="section"><a href="igraph-Random.html#igraph_rng_get_gamma">4.7. <code class="function">igraph_rng_get_gamma</code> — Samples from a gamma distribution.</a></span></dt>
<dt><span class="section"><a href="igraph-Random.html#igraph_rng_get_binom">4.8. <code class="function">igraph_rng_get_binom</code> — Samples from a binomial distribution.</a></span></dt>
<dt><span class="section"><a href="igraph-Random.html#igraph_rng_get_geom">4.9. <code class="function">igraph_rng_get_geom</code> — Samples from a geometric distribution.</a></span></dt>
<dt><span class="section"><a href="igraph-Random.html#igraph_rng_get_pois">4.10. <code class="function">igraph_rng_get_pois</code> — Samples from a Poisson distribution.</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="igraph_rng_get_bool"></a>4.1. <code class="function">igraph_rng_get_bool</code> — Generate a random boolean.</h3></div></div></div>
<a class="indexterm" name="id-1.9.5.2.2"></a><p>
</p>
<div class="informalexample"><pre class="programlisting">
igraph_bool_t igraph_rng_get_bool(igraph_rng_t *rng);
</pre></div>
<p>
</p>
<p>
Use this function only when a single random boolean, i.e. a single bit
is needed at a time. It is not efficient for generating multiple bits.
</p>
<p><b>Arguments: </b>
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code>rng</code></em>:</span></p></td>
<td><p>
Pointer to the RNG to use for the generation. Use <a class="link" href="igraph-Random.html#igraph_rng_default" title="2.1. igraph_rng_default — Query the default random number generator."><code class="function">igraph_rng_default()</code></a> here to use the default igraph RNG.
</p></td>
</tr></tbody>
</table></div>
<p>
</p>
<p><b>Returns: </b></p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
<td><p>
The generated bit, as a truth value.
</p></td>
</tr></tbody>
</table></div>
<p>
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="igraph_rng_get_integer"></a>4.2. <code class="function">igraph_rng_get_integer</code> — Generate an integer random number from an interval.</h3></div></div></div>
<a class="indexterm" name="id-1.9.5.3.2"></a><p>
</p>
<div class="informalexample"><pre class="programlisting">
igraph_int_t igraph_rng_get_integer(
igraph_rng_t *rng, igraph_int_t l, igraph_int_t h
);
</pre></div>
<p>
</p>
<p>
Generate uniformly distributed integers from the interval <code class="literal">[l, h]</code>.
</p>
<p><b>Arguments: </b>
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>rng</code></em>:</span></p></td>
<td><p>
Pointer to the RNG to use for the generation. Use <a class="link" href="igraph-Random.html#igraph_rng_default" title="2.1. igraph_rng_default — Query the default random number generator."><code class="function">igraph_rng_default()</code></a> here to use the default igraph RNG.
</p></td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>l</code></em>:</span></p></td>
<td><p>
Lower limit, inclusive, it can be negative as well.
</p></td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>h</code></em>:</span></p></td>
<td><p>
Upper limit, inclusive, it can be negative as well, but it
must be at least <code class="literal">l</code>.
</p></td>
</tr>
</tbody>
</table></div>
<p>
</p>
<p><b>Returns: </b></p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
<td><p>
The generated random integer.
</p></td>
</tr></tbody>
</table></div>
<p>
Time complexity: O(log2(h-l+1) / bits) where bits is the value of
<a class="link" href="igraph-Random.html#igraph_rng_bits" title="3.4. igraph_rng_bits — The number of random bits that a random number generator can produces in a single round."><code class="function">igraph_rng_bits</code></a>(rng).
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="igraph_rng_get_unif01"></a>4.3. <code class="function">igraph_rng_get_unif01</code> — Samples uniformly from the unit interval.</h3></div></div></div>
<a class="indexterm" name="id-1.9.5.4.2"></a><p>
</p>
<div class="informalexample"><pre class="programlisting">
igraph_real_t igraph_rng_get_unif01(igraph_rng_t *rng);
</pre></div>
<p>
</p>
<p>
Generates uniformly distributed real numbers from the <code class="literal">[0, 1)</code>
half-open interval.
</p>
<p><b>Arguments: </b>
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code>rng</code></em>:</span></p></td>
<td><p>
Pointer to the RNG to use. Use <a class="link" href="igraph-Random.html#igraph_rng_default" title="2.1. igraph_rng_default — Query the default random number generator."><code class="function">igraph_rng_default()</code></a>
here to use the default igraph RNG.
</p></td>
</tr></tbody>
</table></div>
<p>
</p>
<p><b>Returns: </b></p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
<td><p>
The generated uniformly distributed random number.
</p></td>
</tr></tbody>
</table></div>
<p>
Time complexity: depends on the type of the RNG.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="igraph_rng_get_unif"></a>4.4. <code class="function">igraph_rng_get_unif</code> — Samples real numbers from a given interval.</h3></div></div></div>
<a class="indexterm" name="id-1.9.5.5.2"></a><p>
</p>
<div class="informalexample"><pre class="programlisting">
igraph_real_t igraph_rng_get_unif(igraph_rng_t *rng,
igraph_real_t l, igraph_real_t h);
</pre></div>
<p>
</p>
<p>
Generates uniformly distributed real numbers from the <code class="literal">[l, h)</code>
half-open interval.
</p>
<p><b>Arguments: </b>
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>rng</code></em>:</span></p></td>
<td><p>
Pointer to the RNG to use. Use <a class="link" href="igraph-Random.html#igraph_rng_default" title="2.1. igraph_rng_default — Query the default random number generator."><code class="function">igraph_rng_default()</code></a>
here to use the default igraph RNG.
</p></td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>l</code></em>:</span></p></td>
<td><p>
The lower bound, it can be negative.
</p></td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>h</code></em>:</span></p></td>
<td><p>
The upper bound, it can be negative, but it has to be
larger than the lower bound.
</p></td>
</tr>
</tbody>
</table></div>
<p>
</p>
<p><b>Returns: </b></p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
<td><p>
The generated uniformly distributed random number.
</p></td>
</tr></tbody>
</table></div>
<p>
Time complexity: depends on the type of the RNG.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="igraph_rng_get_normal"></a>4.5. <code class="function">igraph_rng_get_normal</code> — Samples from a normal distribution.</h3></div></div></div>
<a class="indexterm" name="id-1.9.5.6.2"></a><p>
</p>
<div class="informalexample"><pre class="programlisting">
igraph_real_t igraph_rng_get_normal(igraph_rng_t *rng,
igraph_real_t m, igraph_real_t s);
</pre></div>
<p>
</p>
<p>
Generates random variates from a normal distribution with probability
density
</p>
<p>
<code class="literal">exp( -(x - m)^2 / (2 s^2) )</code>.
</p>
<p><b>Arguments: </b>
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>rng</code></em>:</span></p></td>
<td><p>
Pointer to the RNG to use. Use <a class="link" href="igraph-Random.html#igraph_rng_default" title="2.1. igraph_rng_default — Query the default random number generator."><code class="function">igraph_rng_default()</code></a>
here to use the default igraph RNG.
</p></td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>m</code></em>:</span></p></td>
<td><p>
The mean.
</p></td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>s</code></em>:</span></p></td>
<td><p>
The standard deviation.
</p></td>
</tr>
</tbody>
</table></div>
<p>
</p>
<p><b>Returns: </b></p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
<td><p>
The generated normally distributed random number.
</p></td>
</tr></tbody>
</table></div>
<p>
Time complexity: depends on the type of the RNG.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="igraph_rng_get_exp"></a>4.6. <code class="function">igraph_rng_get_exp</code> — Samples from an exponential distribution.</h3></div></div></div>
<a class="indexterm" name="id-1.9.5.7.2"></a><p>
</p>
<div class="informalexample"><pre class="programlisting">
igraph_real_t igraph_rng_get_exp(igraph_rng_t *rng, igraph_real_t rate);
</pre></div>
<p>
</p>
<p>
Generates random variates from an exponential distribution with probability
density proportional to
</p>
<p>
<code class="literal">exp(-rate x)</code>.
</p>
<p><b>Arguments: </b>
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>rng</code></em>:</span></p></td>
<td><p>
Pointer to the RNG to use. Use <a class="link" href="igraph-Random.html#igraph_rng_default" title="2.1. igraph_rng_default — Query the default random number generator."><code class="function">igraph_rng_default()</code></a>
here to use the default igraph RNG.
</p></td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>rate</code></em>:</span></p></td>
<td><p>
Rate parameter.
</p></td>
</tr>
</tbody>
</table></div>
<p>
</p>
<p><b>Returns: </b></p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
<td><p>
The generated sample.
</p></td>
</tr></tbody>
</table></div>
<p>
Time complexity: depends on the RNG.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="igraph_rng_get_gamma"></a>4.7. <code class="function">igraph_rng_get_gamma</code> — Samples from a gamma distribution.</h3></div></div></div>
<a class="indexterm" name="id-1.9.5.8.2"></a><p>
</p>
<div class="informalexample"><pre class="programlisting">
igraph_real_t igraph_rng_get_gamma(igraph_rng_t *rng, igraph_real_t shape,
igraph_real_t scale);
</pre></div>
<p>
</p>
<p>
Generates random variates from a gamma distribution with probability
density proportional to
</p>
<p>
<code class="literal">x^(shape-1) exp(-x / scale)</code>.
</p>
<p><b>Arguments: </b>
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>rng</code></em>:</span></p></td>
<td><p>
Pointer to the RNG to use. Use <a class="link" href="igraph-Random.html#igraph_rng_default" title="2.1. igraph_rng_default — Query the default random number generator."><code class="function">igraph_rng_default()</code></a>
here to use the default igraph RNG.
</p></td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>shape</code></em>:</span></p></td>
<td><p>
Shape parameter.
</p></td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>scale</code></em>:</span></p></td>
<td><p>
Scale parameter.
</p></td>
</tr>
</tbody>
</table></div>
<p>
</p>
<p><b>Returns: </b></p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
<td><p>
The generated sample.
</p></td>
</tr></tbody>
</table></div>
<p>
Time complexity: depends on the RNG.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="igraph_rng_get_binom"></a>4.8. <code class="function">igraph_rng_get_binom</code> — Samples from a binomial distribution.</h3></div></div></div>
<a class="indexterm" name="id-1.9.5.9.2"></a><p>
</p>
<div class="informalexample"><pre class="programlisting">
igraph_real_t igraph_rng_get_binom(igraph_rng_t *rng, igraph_int_t n, igraph_real_t p);
</pre></div>
<p>
</p>
<p>
Generates random variates from a binomial distribution. The number <code class="constant">k</code> is generated
with probability
</p>
<p>
<code class="literal">(n \choose k) p^k (1-p)^(n-k)</code>, <code class="literal">k = 0, 1, ..., n</code>.
</p>
<p><b>Arguments: </b>
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>rng</code></em>:</span></p></td>
<td><p>
Pointer to the RNG to use. Use <a class="link" href="igraph-Random.html#igraph_rng_default" title="2.1. igraph_rng_default — Query the default random number generator."><code class="function">igraph_rng_default()</code></a>
here to use the default igraph RNG.
</p></td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>n</code></em>:</span></p></td>
<td><p>
Number of observations.
</p></td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>p</code></em>:</span></p></td>
<td><p>
Probability of an event.
</p></td>
</tr>
</tbody>
</table></div>
<p>
</p>
<p><b>Returns: </b></p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
<td><p>
The generated binomially distributed random number.
</p></td>
</tr></tbody>
</table></div>
<p>
Time complexity: depends on the RNG.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="igraph_rng_get_geom"></a>4.9. <code class="function">igraph_rng_get_geom</code> — Samples from a geometric distribution.</h3></div></div></div>
<a class="indexterm" name="id-1.9.5.10.2"></a><p>
</p>
<div class="informalexample"><pre class="programlisting">
igraph_real_t igraph_rng_get_geom(igraph_rng_t *rng, igraph_real_t p);
</pre></div>
<p>
</p>
<p>
Generates random variates from a geometric distribution. The number <code class="constant">k</code> is
generated with probability
</p>
<p>
<code class="literal">(1 - p)^k p</code>, <code class="literal">k = 0, 1, 2, ...</code>.
</p>
<p><b>Arguments: </b>
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>rng</code></em>:</span></p></td>
<td><p>
Pointer to the RNG to use. Use <a class="link" href="igraph-Random.html#igraph_rng_default" title="2.1. igraph_rng_default — Query the default random number generator."><code class="function">igraph_rng_default()</code></a>
here to use the default igraph RNG.
</p></td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>p</code></em>:</span></p></td>
<td><p>
The probability of success in each trial. Must be larger
than zero and smaller or equal to 1.
</p></td>
</tr>
</tbody>
</table></div>
<p>
</p>
<p><b>Returns: </b></p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
<td><p>
The generated geometrically distributed random number.
</p></td>
</tr></tbody>
</table></div>
<p>
Time complexity: depends on the RNG.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="igraph_rng_get_pois"></a>4.10. <code class="function">igraph_rng_get_pois</code> — Samples from a Poisson distribution.</h3></div></div></div>
<a class="indexterm" name="id-1.9.5.11.2"></a><p>
</p>
<div class="informalexample"><pre class="programlisting">
igraph_real_t igraph_rng_get_pois(igraph_rng_t *rng, igraph_real_t rate);
</pre></div>
<p>
</p>
<p>
Generates random variates from a Poisson distribution. The number <code class="constant">k</code> is generated
with probability
</p>
<p>
<code class="literal">rate^k * exp(-rate) / k!</code>, <code class="literal">k = 0, 1, 2, ...</code>.
</p>
<p><b>Arguments: </b>
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>rng</code></em>:</span></p></td>
<td><p>
Pointer to the RNG to use. Use <a class="link" href="igraph-Random.html#igraph_rng_default" title="2.1. igraph_rng_default — Query the default random number generator."><code class="function">igraph_rng_default()</code></a>
here to use the default igraph RNG.
</p></td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>rate</code></em>:</span></p></td>
<td><p>
The rate parameter of the Poisson distribution. Must not be negative.
</p></td>
</tr>
</tbody>
</table></div>
<p>
</p>
<p><b>Returns: </b></p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
<td><p>
The generated geometrically distributed random number.
</p></td>
</tr></tbody>
</table></div>
<p>
Time complexity: depends on the RNG.
</p>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="supported-random-number-generators"></a>5. Supported random number generators</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="igraph-Random.html#igraph_rngtype_mt19937">5.1. <code class="function">igraph_rngtype_mt19937</code> — The MT19937 random number generator.</a></span></dt>
<dt><span class="section"><a href="igraph-Random.html#igraph_rngtype_glibc2">5.2. <code class="function">igraph_rngtype_glibc2</code> — The random number generator introduced in GNU libc 2.</a></span></dt>
<dt><span class="section"><a href="igraph-Random.html#igraph_rngtype_pcg32">5.3. <code class="function">igraph_rngtype_pcg32</code> — The PCG random number generator (32-bit version).</a></span></dt>
<dt><span class="section"><a href="igraph-Random.html#igraph_rngtype_pcg64">5.4. <code class="function">igraph_rngtype_pcg64</code> — The PCG random number generator (64-bit version).</a></span></dt>
</dl></div>
<p>
By default igraph uses the MT19937 generator. Prior to igraph version
0.6, the generator supplied by the standard C library was used. This
means the GLIBC2 generator on GNU libc 2 systems, and maybe the BSD RAND
generator on others. The RAND generator was removed due to poor statistical
properties in version 0.10. The PCG32 generator was added in version 0.10.
</p>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="igraph_rngtype_mt19937"></a>5.1. <code class="function">igraph_rngtype_mt19937</code> — The MT19937 random number generator.</h3></div></div></div>
<a class="indexterm" name="id-1.9.6.3.2"></a><p>
</p>
<pre class="programlisting">
const igraph_rng_type_t igraph_rngtype_mt19937 = {
/* name= */ "MT19937",
/* bits= */ 32,
/* init= */ igraph_rng_mt19937_init,
/* destroy= */ igraph_rng_mt19937_destroy,
/* seed= */ igraph_rng_mt19937_seed,
/* get= */ igraph_rng_mt19937_get,
/* get_int= */ NULL,
/* get_real= */ NULL,
/* get_norm= */ NULL,
/* get_geom= */ NULL,
/* get_binom= */ NULL,
/* get_exp= */ NULL,
/* get_gamma= */ NULL,
/* get_pois= */ NULL
};
</pre>
<p>
</p>
<p>
The MT19937 generator of Makoto Matsumoto and Takuji Nishimura is a
variant of the twisted generalized feedback shift-register
algorithm, and is known as the “Mersenne Twister” generator. It has
a Mersenne prime period of 2^19937 - 1 (about 10^6000) and is
equi-distributed in 623 dimensions. It has passed the diehard
statistical tests. It uses 624 words of state per generator and is
comparable in speed to the other generators. The original generator
used a default seed of 4357 and choosing <code class="constant">s</code> equal to zero in
<code class="constant">igraph_rng_mt19937_seed</code>() reproduces this. Later versions switched to
5489 as the default seed, you can choose this explicitly via
<a class="link" href="igraph-Random.html#igraph_rng_seed" title="3.3. igraph_rng_seed — Seeds a random number generator."><code class="function">igraph_rng_seed()</code></a> instead if you require it.
</p>
<p>
For more information see,
Makoto Matsumoto and Takuji Nishimura, “Mersenne Twister: A
623-dimensionally equidistributed uniform pseudorandom number
generator”. ACM Transactions on Modeling and Computer Simulation,
Vol. 8, No. 1 (Jan. 1998), Pages 330
</p>
<p>
The generator <code class="constant">igraph_rngtype_mt19937</code> uses the second revision of the
seeding procedure published by the two authors above in 2002. The
original seeding procedures could cause spurious artifacts for some
seed values.
</p>
<p>
This generator was ported from the GNU Scientific Library.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="igraph_rngtype_glibc2"></a>5.2. <code class="function">igraph_rngtype_glibc2</code> — The random number generator introduced in GNU libc 2.</h3></div></div></div>
<a class="indexterm" name="id-1.9.6.4.2"></a><p>
</p>
<pre class="programlisting">
const igraph_rng_type_t igraph_rngtype_glibc2 = {
/* name= */ "LIBC",
/* bits= */ 31,
/* init= */ igraph_rng_glibc2_init,
/* destroy= */ igraph_rng_glibc2_destroy,
/* seed= */ igraph_rng_glibc2_seed,
/* get= */ igraph_rng_glibc2_get,
/* get_int= */ NULL,
/* get_real= */ NULL,
/* get_norm= */ NULL,
/* get_geom= */ NULL,
/* get_binom= */ NULL,
/* get_exp= */ NULL,
/* get_gamma= */ NULL,
/* get_pois= */ NULL
};
</pre>
<p>
</p>
<p>
This is a linear feedback shift register generator with a 128-byte
buffer. This generator was the default prior to igraph version 0.6,
at least on systems relying on GNU libc.
This generator was ported from the GNU Scientific Library. It is a
reimplementation and does not call the system glibc generator.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="igraph_rngtype_pcg32"></a>5.3. <code class="function">igraph_rngtype_pcg32</code> — The PCG random number generator (32-bit version).</h3></div></div></div>
<a class="indexterm" name="id-1.9.6.5.2"></a><p>
</p>
<pre class="programlisting">
const igraph_rng_type_t igraph_rngtype_pcg32 = {
/* name= */ "PCG32",
/* bits= */ 32,
/* init= */ igraph_rng_pcg32_init,
/* destroy= */ igraph_rng_pcg32_destroy,
/* seed= */ igraph_rng_pcg32_seed,
/* get= */ igraph_rng_pcg32_get,
/* get_int= */ NULL,
/* get_real= */ NULL,
/* get_norm= */ NULL,
/* get_geom= */ NULL,
/* get_binom= */ NULL,
/* get_exp= */ NULL,
/* get_gamma= */ NULL,
/* get_pois= */ NULL
};
</pre>
<p>
</p>
<p>
This is an implementation of the PCG random number generator; see
<a class="ulink" href="https://www.pcg-random.org" target="_top">https://www.pcg-random.org</a> for more details. This implementation returns
32 random bits in a single iteration.
</p>
<p>
The generator was ported from the original source code published by the
authors at <a class="ulink" href="https://github.com/imneme/pcg-c" target="_top">https://github.com/imneme/pcg-c</a>.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="igraph_rngtype_pcg64"></a>5.4. <code class="function">igraph_rngtype_pcg64</code> — The PCG random number generator (64-bit version).</h3></div></div></div>
<a class="indexterm" name="id-1.9.6.6.2"></a><p>
</p>
<pre class="programlisting">
const igraph_rng_type_t igraph_rngtype_pcg64 = {
/* name= */ "PCG64",
/* bits= */ 64,
/* init= */ igraph_rng_pcg64_init,
/* destroy= */ igraph_rng_pcg64_destroy,
/* seed= */ igraph_rng_pcg64_seed,
/* get= */ igraph_rng_pcg64_get,
/* get_int= */ NULL,
/* get_real= */ NULL,
/* get_norm= */ NULL,
/* get_geom= */ NULL,
/* get_binom= */ NULL,
/* get_exp= */ NULL,
/* get_gamma= */ NULL,
/* get_pois= */ NULL
};
</pre>
<p>
</p>
<p>
This is an implementation of the PCG random number generator; see
<a class="ulink" href="https://www.pcg-random.org" target="_top">https://www.pcg-random.org</a> for more details. This implementation returns
64 random bits in a single iteration. It is only available on 64-bit plaforms
with compilers that provide the __uint128_t type.
</p>
<p>
PCG64 typically provides better performance than PCG32 when sampling floating
point numbers or very large integers, as it can provide twice as many random
bits in a single generation round.
</p>
<p>
The generator was ported from the original source code published by the
authors at <a class="ulink" href="https://github.com/imneme/pcg-c" target="_top">https://github.com/imneme/pcg-c</a>.
</p>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="random-use-cases"></a>6. Use cases</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="igraph-Random.html#random-normal-use">6.1. Normal (default) use</a></span></dt>
<dt><span class="section"><a href="igraph-Random.html#random-reproducible-simulations">6.2. Reproducible simulations</a></span></dt>
<dt><span class="section"><a href="igraph-Random.html#random-changing-default-generator">6.3. Changing the default generator</a></span></dt>
<dt><span class="section"><a href="igraph-Random.html#random-using-multiple-generators">6.4. Using multiple generators</a></span></dt>
<dt><span class="section"><a href="igraph-Random.html#random-example">6.5. Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="random-normal-use"></a>6.1. Normal (default) use</h3></div></div></div>
<p>
If the user does not use any of the RNG functions explicitly, but calls
some of the randomized igraph functions, then a default RNG is set
up the first time an igraph function needs random numbers. The
seed of this RNG is the output of the <code class="literal">time(0)</code> function
call, using the <code class="literal">time</code> function from the standard C
library. This ensures that igraph creates a different random graph,
each time the C program is called.
</p>
<p>
The created default generator is stored internally and can be
queried with the <a class="link" href="igraph-Random.html#igraph_rng_default" title="2.1. igraph_rng_default — Query the default random number generator."><code class="function">igraph_rng_default()</code></a> function.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="random-reproducible-simulations"></a>6.2. Reproducible simulations</h3></div></div></div>
<p>
If reproducible results are needed, then the user should set the
seed of the default random number generator explicitly, using the
<a class="link" href="igraph-Random.html#igraph_rng_seed" title="3.3. igraph_rng_seed — Seeds a random number generator."><code class="function">igraph_rng_seed()</code></a> function on the default generator, <a class="link" href="igraph-Random.html#igraph_rng_default" title="2.1. igraph_rng_default — Query the default random number generator."><code class="function">igraph_rng_default()</code></a>. When setting the seed to the same number,
igraph generates exactly the same random graph (or series of random
graphs).
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="random-changing-default-generator"></a>6.3. Changing the default generator</h3></div></div></div>
<p>
By default igraph uses the <a class="link" href="igraph-Random.html#igraph_rng_default" title="2.1. igraph_rng_default — Query the default random number generator."><code class="function">igraph_rng_default()</code></a> random number
generator. This can be changed any time by calling <a class="link" href="igraph-Random.html#igraph_rng_set_default" title="2.2. igraph_rng_set_default — Set the default igraph random number generator."><code class="function">igraph_rng_set_default()</code></a>, with an already initialized random number
generator. Note that the old (replaced) generator is not
destroyed, so no memory is deallocated.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="random-using-multiple-generators"></a>6.4. Using multiple generators</h3></div></div></div>
<p>
igraph also provides functions to set up multiple random number
generators, using the <a class="link" href="igraph-Random.html#igraph_rng_init" title="3.1. igraph_rng_init — Initializes a random number generator."><code class="function">igraph_rng_init()</code></a> function, and then
generating random numbers from them, e.g. with <a class="link" href="igraph-Random.html#igraph_rng_get_integer" title="4.2. igraph_rng_get_integer — Generate an integer random number from an interval."><code class="function">igraph_rng_get_integer()</code></a>
and/or <a class="link" href="igraph-Random.html#igraph_rng_get_unif" title="4.4. igraph_rng_get_unif — Samples real numbers from a given interval."><code class="function">igraph_rng_get_unif()</code></a> calls.
</p>
<p>
Note that initializing a new random number generator is
independent of the generator that the igraph functions themselves
use. If you want to replace that, then please use <a class="link" href="igraph-Random.html#igraph_rng_set_default" title="2.2. igraph_rng_set_default — Set the default igraph random number generator."><code class="function">igraph_rng_set_default()</code></a>.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="random-example"></a>6.5. Example</h3></div></div></div>
<p>
</p>
<div class="hideshow" onClick="toggle(this, event)">
<div class="example">
<a name="id-1.9.7.6.2.1"></a><p class="title"><b>Example 8.1.  File <code class="code">examples/simple/random_seed.c</code></b></p>
<div class="example-contents">
<pre class="programlisting"><span class="strong"><strong>#include</strong></span> &lt;igraph.h&gt;
int <span class="strong"><strong>main</strong></span>(void) {
igraph_t g1, g2;
igraph_bool_t iso;
<span class="emphasis"><em>/* Initialize the library. */</em></span>
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_setup" title="4.1. igraph_setup — Initializes the igraph library.">igraph_setup</a></strong></span>();
<span class="emphasis"><em>/* Seed the default random number generator and create a random graph. */</em></span>
<span class="strong"><strong><a class="link" href="igraph-Random.html#igraph_rng_seed" title="3.3. igraph_rng_seed — Seeds a random number generator.">igraph_rng_seed</a></strong></span>(<span class="strong"><strong><a class="link" href="igraph-Random.html#igraph_rng_default" title="2.1. igraph_rng_default — Query the default random number generator.">igraph_rng_default</a></strong></span>(), 1122);
<span class="strong"><strong><a class="link" href="igraph-Games.html#igraph_erdos_renyi_game_gnp" title="1.2. igraph_erdos_renyi_game_gnp — Generates a random (Erdős-Rényi) graph with fixed edge probabilities.">igraph_erdos_renyi_game_gnp</a></strong></span>(&amp;g1, 100, 3.0 / 100, IGRAPH_UNDIRECTED, IGRAPH_SIMPLE_SW, IGRAPH_EDGE_UNLABELED);
<span class="emphasis"><em>/* Seed the generator with the same seed again,</em></span>
<span class="emphasis"><em> * and create a graph with the same method. */</em></span>
<span class="strong"><strong><a class="link" href="igraph-Random.html#igraph_rng_seed" title="3.3. igraph_rng_seed — Seeds a random number generator.">igraph_rng_seed</a></strong></span>(<span class="strong"><strong><a class="link" href="igraph-Random.html#igraph_rng_default" title="2.1. igraph_rng_default — Query the default random number generator.">igraph_rng_default</a></strong></span>(), 1122);
<span class="strong"><strong><a class="link" href="igraph-Games.html#igraph_erdos_renyi_game_gnp" title="1.2. igraph_erdos_renyi_game_gnp — Generates a random (Erdős-Rényi) graph with fixed edge probabilities.">igraph_erdos_renyi_game_gnp</a></strong></span>(&amp;g2, 100, 3.0 / 100, IGRAPH_UNDIRECTED, IGRAPH_SIMPLE_SW, IGRAPH_EDGE_UNLABELED);
<span class="emphasis"><em>/* The two graphs will be identical. */</em></span>
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_is_same_graph" title="6.6. igraph_is_same_graph — Are two graphs identical as labelled graphs?">igraph_is_same_graph</a></strong></span>(&amp;g1, &amp;g2, &amp;iso);
<span class="strong"><strong>if</strong></span> (!iso) {
<span class="strong"><strong>return</strong></span> 1;
}
<span class="emphasis"><em>/* Destroy no longer needed data structures. */</em></span>
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_destroy" title="5.1.4. igraph_destroy — Frees the memory allocated for a graph object.">igraph_destroy</a></strong></span>(&amp;g2);
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_destroy" title="5.1.4. igraph_destroy — Frees the memory allocated for a graph object.">igraph_destroy</a></strong></span>(&amp;g1);
<span class="strong"><strong>return</strong></span> 0;
}
</pre>
<p></p>
</div>
</div>
<br class="example-break">
</div>
</div>
</div>
</div>
<table class="navigation-footer" width="100%" summary="Navigation footer" cellpadding="2" cellspacing="0"><tr valign="middle">
<td align="left"><a accesskey="p" href="igraph-Data-structures.html"><b>← Chapter 7. Data structure library: vector, matrix, other data types</b></a></td>
<td align="right"><a accesskey="n" href="igraph-Iterators.html"><b>Chapter 9. Vertex and edge selectors and sequences, iterators →</b></a></td>
</tr></table>
</body>
</html>