blob: 31d526c65aed234f11f35ce7c59a0ec94b523713 [file] [log] [blame]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Chapter&#160;16.&#160;Boost.Random</title>
<link rel="stylesheet" href="../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="libraries.html" title="Part&#160;I.&#160;The Boost C++ Libraries (BoostBook Subset)">
<link rel="prev" href="proto/appendices.html" title="Appendices">
<link rel="next" href="boost_random/tutorial.html" title="Tutorial">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../boost.png"></td>
<td align="center"><a href="../../index.html">Home</a></td>
<td align="center"><a href="../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="proto/appendices.html"><img src="../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="libraries.html"><img src="../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="boost_random/tutorial.html"><img src="../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="chapter">
<div class="titlepage"><div>
<div><h2 class="title">
<a name="boost_random"></a>Chapter&#160;16.&#160;Boost.Random</h2></div>
<div><div class="author"><h3 class="author">
<span class="firstname">Jens</span> <span class="surname">Maurer</span>
</h3></div></div>
<div><p class="copyright">Copyright &#169; 2000 -2005 Jens Maurer, 2009 Steven Watanabe</p></div>
<div><div class="legalnotice">
<a name="id2462665"></a><p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></div>
</div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl>
<dt><span class="section"><a href="boost_random.html#boost_random.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_random/tutorial.html">Tutorial</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="boost_random/tutorial.html#boost_random.tutorial.generating_integers_in_a_range">Generating
integers in a range</a></span></dt>
<dt><span class="section"><a href="boost_random/tutorial.html#boost_random.tutorial.generating_integers_with_different_probabilities">Generating
integers with different probabilities</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="boost_random/reference.html">Reference</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="boost_random/reference.html#boost_random.reference.concepts">Concepts</a></span></dt>
<dt><span class="section"><a href="boost_random/reference.html#boost_random.reference.generators">Generators</a></span></dt>
<dt><span class="section"><a href="boost_random/reference.html#boost_random.reference.distributions">Distributions</a></span></dt>
<dt><span class="section"><a href="boost_random/reference.html#headers">Headers</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="boost_random/performance.html">Performance</a></span></dt>
<dt><span class="section"><a href="boost_random/rationale.html">Rationale</a></span></dt>
<dt><span class="section"><a href="boost_random/history_and_acknowledgements.html">History and
Acknowledgements</a></span></dt>
</dl>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="boost_random.introduction"></a><a class="link" href="boost_random.html#boost_random.introduction" title="Introduction">Introduction</a>
</h2></div></div></div>
<p>
Random numbers are useful in a variety of applications. The Boost Random Number
Library (Boost.Random for short) provides a variety of <a class="link" href="boost_random/reference.html#boost_random.reference.generators" title="Generators">generators</a>
and <a class="link" href="boost_random/reference.html#boost_random.reference.distributions" title="Distributions">distributions</a>
to produce random numbers having useful properties, such as uniform distribution.
</p>
<p>
You should read the <a class="link" href="boost_random/reference.html#boost_random.reference.concepts" title="Concepts">concepts
documentation</a> for an introduction and the definition of the basic concepts.
For a quick start, it may be sufficient to have a look at <a href="../../libs/random/example/random_demo.cpp" target="_top">random_demo.cpp</a>.
</p>
<p>
For a very quick start, here's an example:
</p>
<pre class="programlisting"><code class="computeroutput"><a class="link" href="boost/mt19937.html" title="Type definition mt19937">boost::mt19937</a></code> <span class="identifier">rng</span><span class="special">;</span> <span class="comment">// produces randomness out of thin air
</span> <span class="comment">// see pseudo-random number generators
</span><code class="computeroutput"><a class="link" href="boost/uniform_int.html" title="Class template uniform_int">boost::uniform_int</a></code>&lt;&gt; <span class="identifier">six</span><span class="special">(</span><span class="number">1</span><span class="special">,</span><span class="number">6</span><span class="special">);</span> <span class="comment">// distribution that maps to 1..6
</span> <span class="comment">// see random number distributions
</span><code class="computeroutput"><a class="link" href="boost/variate_generator.html" title="Class template variate_generator">boost::variate_generator</a></code><span class="special">&lt;</span><code class="computeroutput"><a class="link" href="boost/mt19937.html" title="Type definition mt19937">boost::mt19937</a></code><span class="special">&amp;,</span> <code class="computeroutput"><a class="link" href="boost/uniform_int.html" title="Class template uniform_int">boost::uniform_int</a></code><span class="special">&lt;&gt;</span> <span class="special">&gt;</span>
<span class="identifier">die</span><span class="special">(</span><span class="identifier">rng</span><span class="special">,</span> <span class="identifier">six</span><span class="special">);</span> <span class="comment">// glues randomness with mapping
</span><span class="keyword">int</span> <span class="identifier">x</span> <span class="special">=</span> <span class="identifier">die</span><span class="special">();</span> <span class="comment">// simulate rolling a die
</span></pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"><p><small>Last revised: November 10, 2010 at 00:45:18 GMT</small></p></td>
<td align="right"><div class="copyright-footer"></div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="proto/appendices.html"><img src="../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="libraries.html"><img src="../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="boost_random/tutorial.html"><img src="../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>