The class Random is a random numbers generator. It generates uniformly distributed random bools, ints and doubles. It can be used as the random number generating function object in the STL algorithm random_shuffle.
Instances of Random can be seen as input streams. Different streams are independent of each other, i.e. the sequence of numbers from one stream does not depend upon how many numbers were extracted from the other streams. At each time, an instance has a state that uniquely determines the subsequent numbers being produced.
It can be very useful, e.g. for debugging, to reproduce a sequence of random numbers. This can be done by either initialising with a fixed seed, or by using the state functions as described below.
#include <CGAL/Random.h>
| |
The State type.
|
| |
introduces a variable random of type Random. The
seed is chosen ``randomly'', depending on the system time.
| |
| |
introduces a variable random of type Random and initializes its internal state using seed. Equal
values for seed result in equal sequences of random
numbers.
|
|
| returns a random bool. |
| ||
|
| returns a random int value from the interval [0,2^b). This is supposed to be efficient. |
|
| |
returns a random int from the interval [lower,upper). | ||
|
| |
returns a random double from the interval [lower,upper). |
The following member functions are a 1-to-1 correspondence to some distributions from the boost random library.
| ||
|
| |
returns a random IntType from the interval [lower,upper]. IntType can be an integral type as int, std::ptrdiff_t, std::size_t,etc. Warning: In contrast to get_int this function may return upper. | ||
| ||
|
| |
returns a random IntType from the interval [lower,upper]. IntType can be an integral type as int, std::ptrdiff_t, std::size_t,etc. Warning: In contrast to get_int this function may return upper. | ||
| ||
|
| |
returns a random RealType from the interval [lower,upper). RealType can be float, double, etc. | ||
| ||
|
| returns a random RealType from the interval [0,1). RealType can be float, double, etc. |
| ||
|
| returns randomuniform_int<IntType>( 0, upper-1). |
|
| returns the seed used for initialization. |
|
| |
saves the current internal state in state. | ||
|
| |
restores the internal state from state. |
|
| returns true, iff random and random2 have equal internal states. |
We use the boost random library function boost::rand48 to generate the random numbers.