You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
148 lines
7.7 KiB
HTML
148 lines
7.7 KiB
HTML
4 years ago
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||
|
<html>
|
||
|
<!-- This manual describes how to install and use the GNU multiple precision
|
||
|
arithmetic library, version 6.1.0.
|
||
|
|
||
|
Copyright 1991, 1993-2015 Free Software Foundation, Inc.
|
||
|
|
||
|
Permission is granted to copy, distribute and/or modify this document under
|
||
|
the terms of the GNU Free Documentation License, Version 1.3 or any later
|
||
|
version published by the Free Software Foundation; with no Invariant Sections,
|
||
|
with the Front-Cover Texts being "A GNU Manual", and with the Back-Cover
|
||
|
Texts being "You have freedom to copy and modify this GNU Manual, like GNU
|
||
|
software". A copy of the license is included in
|
||
|
GNU Free Documentation License. -->
|
||
|
<!-- Created by GNU Texinfo 6.4, http://www.gnu.org/software/texinfo/ -->
|
||
|
<head>
|
||
|
<title>C++ Interface Random Numbers (GNU MP 6.1.0)</title>
|
||
|
|
||
|
<meta name="description" content="How to install and use the GNU multiple precision arithmetic library, version 6.1.0.">
|
||
|
<meta name="keywords" content="C++ Interface Random Numbers (GNU MP 6.1.0)">
|
||
|
<meta name="resource-type" content="document">
|
||
|
<meta name="distribution" content="global">
|
||
|
<meta name="Generator" content="makeinfo">
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||
|
<link href="index.html#Top" rel="start" title="Top">
|
||
|
<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
|
||
|
<link href="C_002b_002b-Class-Interface.html#C_002b_002b-Class-Interface" rel="up" title="C++ Class Interface">
|
||
|
<link href="C_002b_002b-Interface-Limitations.html#C_002b_002b-Interface-Limitations" rel="next" title="C++ Interface Limitations">
|
||
|
<link href="C_002b_002b-Interface-Floats.html#C_002b_002b-Interface-Floats" rel="prev" title="C++ Interface Floats">
|
||
|
<style type="text/css">
|
||
|
<!--
|
||
|
a.summary-letter {text-decoration: none}
|
||
|
blockquote.indentedblock {margin-right: 0em}
|
||
|
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
|
||
|
blockquote.smallquotation {font-size: smaller}
|
||
|
div.display {margin-left: 3.2em}
|
||
|
div.example {margin-left: 3.2em}
|
||
|
div.lisp {margin-left: 3.2em}
|
||
|
div.smalldisplay {margin-left: 3.2em}
|
||
|
div.smallexample {margin-left: 3.2em}
|
||
|
div.smalllisp {margin-left: 3.2em}
|
||
|
kbd {font-style: oblique}
|
||
|
pre.display {font-family: inherit}
|
||
|
pre.format {font-family: inherit}
|
||
|
pre.menu-comment {font-family: serif}
|
||
|
pre.menu-preformatted {font-family: serif}
|
||
|
pre.smalldisplay {font-family: inherit; font-size: smaller}
|
||
|
pre.smallexample {font-size: smaller}
|
||
|
pre.smallformat {font-family: inherit; font-size: smaller}
|
||
|
pre.smalllisp {font-size: smaller}
|
||
|
span.nolinebreak {white-space: nowrap}
|
||
|
span.roman {font-family: initial; font-weight: normal}
|
||
|
span.sansserif {font-family: sans-serif; font-weight: normal}
|
||
|
ul.no-bullet {list-style: none}
|
||
|
-->
|
||
|
</style>
|
||
|
|
||
|
|
||
|
</head>
|
||
|
|
||
|
<body lang="en">
|
||
|
<a name="C_002b_002b-Interface-Random-Numbers"></a>
|
||
|
<div class="header">
|
||
|
<p>
|
||
|
Next: <a href="C_002b_002b-Interface-Limitations.html#C_002b_002b-Interface-Limitations" accesskey="n" rel="next">C++ Interface Limitations</a>, Previous: <a href="C_002b_002b-Interface-Floats.html#C_002b_002b-Interface-Floats" accesskey="p" rel="prev">C++ Interface Floats</a>, Up: <a href="C_002b_002b-Class-Interface.html#C_002b_002b-Class-Interface" accesskey="u" rel="up">C++ Class Interface</a> [<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
|
||
|
</div>
|
||
|
<hr>
|
||
|
<a name="C_002b_002b-Interface-Random-Numbers-1"></a>
|
||
|
<h3 class="section">12.5 C++ Interface Random Numbers</h3>
|
||
|
|
||
|
<dl>
|
||
|
<dt><a name="index-gmp_005frandclass"></a>Class: <strong>gmp_randclass</strong></dt>
|
||
|
<dd><p>The C++ class interface to the GMP random number functions uses
|
||
|
<code>gmp_randclass</code> to hold an algorithm selection and current state, as per
|
||
|
<code>gmp_randstate_t</code>.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<dl>
|
||
|
<dt><a name="index-gmp_005frandclass_003a_003agmp_005frandclass"></a>Function: <em></em> <strong>gmp_randclass::gmp_randclass</strong> <em>(void (*<var>randinit</var>) (gmp_randstate_t, …), …)</em></dt>
|
||
|
<dd><p>Construct a <code>gmp_randclass</code>, using a call to the given <var>randinit</var>
|
||
|
function (see <a href="Random-State-Initialization.html#Random-State-Initialization">Random State Initialization</a>). The arguments expected are
|
||
|
the same as <var>randinit</var>, but with <code>mpz_class</code> instead of <code>mpz_t</code>.
|
||
|
For example,
|
||
|
</p>
|
||
|
<div class="example">
|
||
|
<pre class="example">gmp_randclass r1 (gmp_randinit_default);
|
||
|
gmp_randclass r2 (gmp_randinit_lc_2exp_size, 32);
|
||
|
gmp_randclass r3 (gmp_randinit_lc_2exp, a, c, m2exp);
|
||
|
gmp_randclass r4 (gmp_randinit_mt);
|
||
|
</pre></div>
|
||
|
|
||
|
<p><code>gmp_randinit_lc_2exp_size</code> will fail if the size requested is too big,
|
||
|
an <code>std::length_error</code> exception is thrown in that case.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<dl>
|
||
|
<dt><a name="index-gmp_005frandclass_003a_003agmp_005frandclass-1"></a>Function: <em></em> <strong>gmp_randclass::gmp_randclass</strong> <em>(gmp_randalg_t <var>alg</var>, …)</em></dt>
|
||
|
<dd><p>Construct a <code>gmp_randclass</code> using the same parameters as
|
||
|
<code>gmp_randinit</code> (see <a href="Random-State-Initialization.html#Random-State-Initialization">Random State Initialization</a>). This function is
|
||
|
obsolete and the above <var>randinit</var> style should be preferred.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<dl>
|
||
|
<dt><a name="index-gmp_005frandclass_003a_003aseed"></a>Function: <em>void</em> <strong>gmp_randclass::seed</strong> <em>(unsigned long int <var>s</var>)</em></dt>
|
||
|
<dt><a name="index-gmp_005frandclass_003a_003aseed-1"></a>Function: <em>void</em> <strong>gmp_randclass::seed</strong> <em>(mpz_class <var>s</var>)</em></dt>
|
||
|
<dd><p>Seed a random number generator. See see <a href="Random-Number-Functions.html#Random-Number-Functions">Random Number Functions</a>, for how
|
||
|
to choose a good seed.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<dl>
|
||
|
<dt><a name="index-gmp_005frandclass_003a_003aget_005fz_005fbits"></a>Function: <em>mpz_class</em> <strong>gmp_randclass::get_z_bits</strong> <em>(mp_bitcnt_t <var>bits</var>)</em></dt>
|
||
|
<dt><a name="index-gmp_005frandclass_003a_003aget_005fz_005fbits-1"></a>Function: <em>mpz_class</em> <strong>gmp_randclass::get_z_bits</strong> <em>(mpz_class <var>bits</var>)</em></dt>
|
||
|
<dd><p>Generate a random integer with a specified number of bits.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<dl>
|
||
|
<dt><a name="index-gmp_005frandclass_003a_003aget_005fz_005frange"></a>Function: <em>mpz_class</em> <strong>gmp_randclass::get_z_range</strong> <em>(mpz_class <var>n</var>)</em></dt>
|
||
|
<dd><p>Generate a random integer in the range 0 to <em><var>n</var>-1</em> inclusive.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<dl>
|
||
|
<dt><a name="index-gmp_005frandclass_003a_003aget_005ff"></a>Function: <em>mpf_class</em> <strong>gmp_randclass::get_f</strong> <em>()</em></dt>
|
||
|
<dt><a name="index-gmp_005frandclass_003a_003aget_005ff-1"></a>Function: <em>mpf_class</em> <strong>gmp_randclass::get_f</strong> <em>(mp_bitcnt_t <var>prec</var>)</em></dt>
|
||
|
<dd><p>Generate a random float <var>f</var> in the range <em>0 <= <var>f</var> < 1</em>. <var>f</var>
|
||
|
will be to <var>prec</var> bits precision, or if <var>prec</var> is not given then to
|
||
|
the precision of the destination. For example,
|
||
|
</p>
|
||
|
<div class="example">
|
||
|
<pre class="example">gmp_randclass r;
|
||
|
...
|
||
|
mpf_class f (0, 512); // 512 bits precision
|
||
|
f = r.get_f(); // random number, 512 bits
|
||
|
</pre></div>
|
||
|
</dd></dl>
|
||
|
|
||
|
|
||
|
|
||
|
<hr>
|
||
|
<div class="header">
|
||
|
<p>
|
||
|
Next: <a href="C_002b_002b-Interface-Limitations.html#C_002b_002b-Interface-Limitations" accesskey="n" rel="next">C++ Interface Limitations</a>, Previous: <a href="C_002b_002b-Interface-Floats.html#C_002b_002b-Interface-Floats" accesskey="p" rel="prev">C++ Interface Floats</a>, Up: <a href="C_002b_002b-Class-Interface.html#C_002b_002b-Class-Interface" accesskey="u" rel="up">C++ Class Interface</a> [<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
|
||
|
</div>
|
||
|
|
||
|
|
||
|
|
||
|
</body>
|
||
|
</html>
|