Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

Chapter 16. Boost.Random

Jens Maurer

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

Table of Contents

Introduction
Tutorial
Generating integers in a range
Generating integers with different probabilities
Reference
Concepts
Generators
Distributions
Headers
Performance
Rationale
History and Acknowledgements

Random numbers are useful in a variety of applications. The Boost Random Number Library (Boost.Random for short) provides a variety of generators and distributions to produce random numbers having useful properties, such as uniform distribution.

You should read the concepts documentation for an introduction and the definition of the basic concepts. For a quick start, it may be sufficient to have a look at random_demo.cpp.

For a very quick start, here's an example:

boost::mt19937 rng;                 // produces randomness out of thin air
                                    // see pseudo-random number generators
boost::uniform_int<> six(1,6);      // distribution that maps to 1..6
                                    // see random number distributions
boost::variate_generator<boost::mt19937&, boost::uniform_int<> >
         die(rng, six);             // glues randomness with mapping
int x = die();                      // simulate rolling a die

Last revised: August 12, 2010 at 21:43:00 GMT


PrevUpHomeNext