Navigation: Up, Table of Contents, Bibliography, Index, Title Page

Random Numbers Generator (CGAL_Random)

Definition

An instance of type CGAL_Random is a random numbers generator. It allows to generate 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 CGAL_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.

It can be very useful, e.g. for debugging, to reproduce a sequence of random numbers. This can be done by either initializing deterministically or using the seed functions as described below.

#include <CGAL/Random.h>

Global Variables

CGAL_Random CGAL_random; This global variable is used as the default random numbers generator.

Types

CGAL_Random::Seed
Seed type.

Creation

CGAL_Random random;
introduces a variable random of type CGAL_Random.

CGAL_Random random ( Seed seed);
introduces a variable random of type CGAL_Random and initializes its internal seed with seed.

CGAL_Random random ( long init);
introduces a variable random of type CGAL_Random and initializes its internal seed using init. Equal values for init result in equal sequences of random numbers.

Operations

bool random.get_bool () returns a random bool.
int random.get_int ( int lower, int upper)
returns a random int from the interval [lower,upper).
double
random.get_double ( double lower = 0.0,
double upper = 1.0)
returns a random double from [lower,upper).
int random ( int upper)
returns random.get_int( 0, upper).

Seed Functions

void random.save_seed ( Seed& seed)
saves the current internal seed in seed.
void random.restore_seed ( Seed seed)
restores the internal seed from seed.

Equality Test

bool random == random2 returns true, iff random and random2 have equal internal seeds.

Implementation

We use the C library function erand48 to generate the random numbers, i.e. the sequence of numbers depends on the implementation of erand48 on your specific platform.


Next: Class declaration of Point_generator
Navigation: Up, Table of Contents, Bibliography, Index, Title Page
The CGAL Project. 22 January 1999.