random.h File Reference

Introduction

Definition of basic randomization functions.

See also
random.c.

Definition in file random.h.

Macros

#define DEBUG_RANDOM   (_DEBUG>4?1:0)
 Debug the radom generation of numbers. More...
 

Functions

void randomReset ()
 Resets the random seed. More...
 
void randomSet (unsigned int seed)
 Sets the random seed. More...
 
double randomDouble ()
 Returns a random double in the [0,1] interval. More...
 
double randomNormal ()
 Returns a random double acording to a normal distribution. More...
 
double randomInInterval (Tinterval *t)
 Returns a random double in the given interval. More...
 
unsigned int randomMax (unsigned int m)
 Returns a random integer in the range [0,m]. More...
 
unsigned int randomWithDistribution (unsigned int m, double s, double *d)
 Random number with a given discrete distribution. More...
 
void randomOnBall (double r, unsigned int k, double *p)
 Random number on a k dimensional ball. More...
 
void randomInBall (double r, unsigned int k, double *p)
 Random number in a k dimensional ball. More...
 
void randomVector (unsigned int n, double *v)
 Random vector. More...
 

Macro Definition Documentation

◆ DEBUG_RANDOM

#define DEBUG_RANDOM   (_DEBUG>4?1:0)

Used to debug the random generation of numbers.

Definition at line 12 of file random.h.

Function Documentation

◆ randomReset()

void randomReset ( )

Resets the random seed using the current time so, in principle, the reset is hard to predict.

Definition at line 18 of file random.c.

References randomSet().

Referenced by main().

◆ randomSet()

void randomSet ( unsigned int  seed)

Sets the random to the given value. This is used to get repetitive sequences of random numbers in order to debug mainly.

Please, note that when using advanced numerical libraries (BLAS) the result of numerical computations can be different at each run (https://bebop.cs.berkeley.edu/reproblas). The differences are tiny (at the machine precision) but in some systems (specially with dynamics) such errors can accumulate and produce a different result in each run.

To avoid this, you can increase the DEBUG level (in the main CMake file) since then BLAS is not used. However, parallelism will not be used either and the execution will be much slower.

Parameters
seedThe new random seed.

Definition at line 23 of file random.c.

Referenced by main(), and randomReset().

◆ randomDouble()

double randomDouble ( )

◆ randomNormal()

double randomNormal ( )

Returns a random number following a normal distribution with mean 0 and standard deviation 1.

Returns
A random double.

Definition at line 46 of file random.c.

References FALSE, randomDouble(), and TRUE.

Referenced by randomInBall(), and randomOnBall().

◆ randomInInterval()

double randomInInterval ( Tinterval t)

Returns a random number in the given interval selected with a uniform distribution.

Parameters
tThe interval where to drawn the random sample.
Returns
A random double in the given interval.

Definition at line 83 of file random.c.

References LowerLimit(), randomDouble(), and UpperLimit().

Referenced by CuikGradientInBox(), CuikNewtonInBox(), IncrementalSampleCuikSystemInBox(), RandomPointInBox(), RandomPointInPolytope(), and SampleCuikSystemInBox().

◆ randomMax()

unsigned int randomMax ( unsigned int  m)

Returns a random integer in the range [0,m] selected with a uniform distribution. Observe that m is included as a possible outcome.

Parameters
mThe upper limit for the random generator.
Returns
The randomly selected integer in [0,m].

Definition at line 99 of file random.c.

References randomDouble().

Referenced by AddBranchToAtlasDynamicRRT(), ComputeSplitDimInt(), IncrementalSampleCuikSystemInBox(), kinoEST(), PolytopeBoundaryPointFromExternalCorner(), RandomPointInAtlas(), RandomPointInAtlasTree(), RandomSmooth(), and SmoothPathInAtlasRRT().

◆ randomWithDistribution()

unsigned int randomWithDistribution ( unsigned int  m,
double  s,
double *  d 
)

Gets a random number following an arbitrary random discrete distribution.

Parameters
mThe size of the distribution (number of options).
sSum of the values in d. If zero the sum is computed inside this function.
dThe value for each option. The values in d are assume possitive but not normalized.

Definition at line 118 of file random.c.

References randomDouble().

Referenced by RandomPointInAtlas(), and RandomPointInAtlasTree().

◆ randomOnBall()

void randomOnBall ( double  r,
unsigned int  k,
double *  p 
)

Selects a random point on the surface of a k dimensional ball with uniform distribution.

Parameters
rRadius of the ball.
kDimension of the space where the ball is defiend.
pSpace for the output point. Must be allocated externally.

Definition at line 146 of file random.c.

References randomNormal().

Referenced by PolytopeRandomPointOnBoundary(), and SPolytopeRandomPointOnBoundary().

◆ randomInBall()

void randomInBall ( double  r,
unsigned int  k,
double *  p 
)

Selects a random point inside a k dimensional ball with uniform distribution.

Parameters
rRadius of the ball.
kDimension of the space where the ball is defiend.
pSpace for the output point. Must be allocated externally.

Definition at line 166 of file random.c.

References randomDouble(), and randomNormal().

Referenced by RandomPointInSPolytope(), and SPolytopeVolume().

◆ randomVector()

void randomVector ( unsigned int  n,
double *  v 
)

Random vector with numbers uniformly distributed in the [0,1] interval.

Parameters
nThe size fo the vector.
vThe vector to fill.

Definition at line 189 of file random.c.

References randomDouble().