Contents
Random number generators

Overview

Convenience wrappers around the C++11 random number generator library.

The implementation is based around a single RandomNumberGenerator template class. A set of aliases are provided for each of the random number generator configurations.

The defined random number configurations are given in the table towards the end of this chapter.

Quick start

#include <Balau/Util/Random.hpp>

Construction

To create a RandomNumberGenerator, choose the configuration you require and supply the boundaries within which the generator will generate numbers.

			// Create a uniform double random number generator that will generate
			// double precision floating point numbers between 0 and 10.
			UniformDouble random(0, 10);
		

There is a second constructor available that takes an integer seed value in order to allow for repeatability (useful for testing).

			// Create a uniform double random number generator with a seed.
			UniformDouble random(0, 10, 12345);
		

Usage

Once constructed, random numbers can be obtained from the generator by calling its operator ().

			// Generate some random numbers.
			double a = random();
			double b = random();
			double c = random();
		

Generator types

This section lists the different types of generated that are defined.

Uniform distribution

Name Description
UniformDouble A uniform distribution, double precision floating point random number generator.
UniformFloat A uniform distribution, single precision floating point random number generator.
UniformInt32 A uniform distribution, 32 bit signed integer floating point random number generator.
UniformInt64 A uniform distribution, 64 bit signed integer floating point random number generator.
UniformUInt32 A uniform distribution, 32 bit signed integer floating point random number generator.
UniformUInt64 A uniform distribution, 64 bit signed integer floating point random number generator.

Normal distribution

Name Description
NormalDouble A normal distribution, double precision floating point random number generator.
NormalFloat A normal distribution, single precision floating point random number generator.

Templated types

These templated aliases require the type T to be specified. Most developers will not require these.

Name Description
UniformReal A uniform distribution, floating point random number generator.
UniformInt A uniform distribution, integer random number generator.
Normal A normal distribution random number generator.
LogNormal A log normal distribution random number generator.
Gamma A gamma distribution random number generator.
ChiSquared A chi squared distribution random number generator.
Cauchy A Cauchy distribution random number generator.
FisherF A Fisher F distribution random number generator.
StudentT A Student T distribution random number generator.
Binomial A discrete binomial distribution random number generator.
Geometric A geometric distribution random number generator.
NegativeBinomial A negative binomial distribution random number generator.
Poisson A Poisson distribution random number generator.
Exponential An exponential distribution random number generator.
Weibull A Weibull distribution random number generator.
ExtremeValue An extreme value distribution random number generator.
Discrete A discrete distribution random number generator.
PiecewiseConstant A piecewise constant distribution random number generator.
PiecewiseLinear A piecewise linear distribution random number generator.

Apart from the numeric template type, the use of the templated generators is the same as the fully typed generators.

			// Create a double precision Poisson random number generator.
			Poisson<double> random(0, 10);

			double a = random();
			double b = random();
			double c = random();