Bsoft 2.1.4
Bernard's software package
random_numbers.h File Reference

Header file for functions for creating random images. More...

#include <Vector3.h>

Functions

long get_rand_max ()
 Finds the maximum random number for a system. More...
 
long random_seed ()
 Gets a random seed and sets the flag. More...
 
float * random_array_uniform (long n, double min, double max)
 Generates a series with a uniform random distribution. More...
 
double random_gaussian (double avg, double std)
 Generates a value with a gaussian random distribution. More...
 
float * random_array_gaussian (long n, double avg, double std)
 Generates a series with a gaussian random distribution of values. More...
 
double random_poisson (double avg)
 Generates a value deviating from the average based on a poisson distribution. More...
 
float * random_array_poisson (int n, double avg)
 Generates a series with a poisson random distribution of values. More...
 
double random_logistical (double avg, double std)
 Generates a value with a logistical random distribution. More...
 
float * random_array_logistical (long n, double avg, double std)
 Generates an array with a logistical random distribution. More...
 
Vector3< double > vector3_random_unit_sphere ()
 Generates a random vector on the unit sphere. More...
 
Vector3< double > vector3_random (const double min, const double max)
 Generates a random vector within a defined cube. More...
 
Vector3< double > vector3_random (Vector3< double > min, Vector3< double > max)
 Generates a random vector within a defined cube. More...
 
Vector3< double > vector3_random (const double length)
 Generates a random vector within a defined sphere. More...
 
Vector3< double > vector3_random_gaussian (double avg, double std)
 Generates a random vector within a random gaussian-distributed length. More...
 
Vector3< double > vector3_xy_random_gaussian (double avg, double std)
 Generates a random vector within a random gaussian-distributed length in the xy plane. More...
 

Detailed Description

Header file for functions for creating random images.

Author
Bernard Heymann
Date
Created: 19990703
Modified: 20151113

Function Documentation

◆ get_rand_max()

long get_rand_max ( )

Finds the maximum random number for a system.

Returns
long the maximum random number.
Loops through random numbers to determine if the maximum is 2 or 4 bytes.

◆ random_array_gaussian()

float * random_array_gaussian ( long  n,
double  avg,
double  stdev 
)

Generates a series with a gaussian random distribution of values.

Parameters
nnumber of values.
avgaverage.
stdevstandard deviation.
Returns
float* the array of values.
An array of floating point numbers is generated with a gaussian 
distribution with a given average and standard deviation:
    value = average + std_dev*sqrt(-2*log(random_value))*
                    cos(2*PI*random_value);
where random_value is between 0 and 1.

◆ random_array_logistical()

float * random_array_logistical ( long  n,
double  avg,
double  stdev 
)

Generates an array with a logistical random distribution.

Parameters
nnumber of values.
avgaverage.
stdevstandard deviation.
Returns
float* array of values.
An array of floating point numbers is generated with a logistical 
differential distribution with a given average and standard deviation:
    value = average + (std_dev/golden)*ln(1/random_value - 1)
where random_value is between 0 and 1 and:
    golden  = (sqrt(5) + 1)/2
Reference: Press W.H. et al (1992) Numerical Recipes in C.

◆ random_array_poisson()

float * random_array_poisson ( int  n,
double  avg 
)

Generates a series with a poisson random distribution of values.

Parameters
nnumber of values.
avgaverage.
Returns
float* the array of values.
The poisson distribution is given for j = 0,1,... by:
            avg^j * exp(-avg)
    P(j) = -----------------
                   j!
Note that only positive integer values are defined for j and sum(P(j)) = 1.
An array of floating point numbers is generated with a poisson 
distribution with a given average. The standard deviation is:
    std = sqrt(avg)
If the average <= 0, the return array contains only zeroes.
Reference: Press W.H. et al (1992) Numerical Recipes in C.

◆ random_array_uniform()

float * random_array_uniform ( long  n,
double  min,
double  max 
)

Generates a series with a uniform random distribution.

Parameters
nnumber of values.
minminimum value.
maxmaximum value.
Returns
float* array with uniform random numbers.
An array of floating point numbers is generated distributed uniformly 
in the range of the given minimum and maximum:
    value = random_value*(max - min) + min
where random_value is between 0 and 1.
The average and standard deviation are:
    average = (max + min)/2
    standard deviation = 0.5*sqrt(1/3)*(max - min).

◆ random_gaussian()

double random_gaussian ( double  avg,
double  stdev 
)

Generates a value with a gaussian random distribution.

Parameters
avgaverage.
stdevstandard deviation.
Returns
double the random value.
A floating point number is generated with a gaussian 
distribution with a given average and standard deviation:
    value = average + std_dev*sqrt(-2*log(random_value))*
                    cos(2*PI*random_value);
where random_value is between 0 and 1.

◆ random_logistical()

double random_logistical ( double  avg,
double  stdev 
)

Generates a value with a logistical random distribution.

Parameters
avgaverage.
stdevstandard deviation.
Returns
double the random value.
A floating point number is generated with a logistical 
differential distribution with a given average and standard deviation:
    value = average + (std_dev/golden)*ln(1/random_value - 1)
where random_value is between 0 and 1 and:
    golden  = (sqrt(5) + 1)/2
Reference: Press W.H. et al (1992) Numerical Recipes in C.

◆ random_poisson()

double random_poisson ( double  avg)

Generates a value deviating from the average based on a poisson distribution.

Parameters
avgaverage.
Returns
double value.
The poisson distribution is given for j = 0,1,... by:
            avg^j * exp(-avg)
    P(j) = -----------------
                   j!
Note that only positive integer values are defined for j and sum(P(j)) = 1.
A value is generated with a poisson distribution with a given average.
If the average <= 0, the return value is zero.
Reference: Press W.H. et al (1992) Numerical Recipes in C.

◆ random_seed()

long random_seed ( )

Gets a random seed and sets the flag.

Returns
int flag.
The random seed is obtained using the program pid.
A flag is set to prevent the seed from being generated multiple times.

◆ vector3_random() [1/3]

Vector3< double > vector3_random ( const double  length)

Generates a random vector within a defined sphere.

Parameters
lengthmaximum vector length.
Returns
Vector3<double> vector.
A random vector is generated, normalized and multiplied with
a random value smaller than the given length.

◆ vector3_random() [2/3]

Vector3< double > vector3_random ( const double  min,
const double  max 
)

Generates a random vector within a defined cube.

Parameters
minminimum.
maxmaximum.
Returns
Vector3<double> vector.
Each vector element is set to a random value between the given minimum and maximum.

◆ vector3_random() [3/3]

Vector3< double > vector3_random ( Vector3< double >  min,
Vector3< double >  max 
)

Generates a random vector within a defined cube.

Parameters
minminimum vector.
maxmaximum vector.
Returns
Vector3<double> vector.
Each vector element is set to a random value between the given 
minimum and maximum vectors.

◆ vector3_random_gaussian()

Vector3< double > vector3_random_gaussian ( double  avg,
double  stdev 
)

Generates a random vector within a random gaussian-distributed length.

Parameters
avgaverage of gaussian distribution.
stdevstandard deviation of gaussian distribution.
Returns
Vector3<double> vector.
A random vector is generated, normalized and multiplied with
a random value derived from a gaussian distribution.

◆ vector3_random_unit_sphere()

Vector3< double > vector3_random_unit_sphere ( )

Generates a random vector on the unit sphere.

Returns
Vector3<double> vector.
A random vector is generated with a uniform distribution on the unit sphere.
Reference: Press W.H. et al (1992) Numerical Recipes in C.

◆ vector3_xy_random_gaussian()

Vector3< double > vector3_xy_random_gaussian ( double  avg,
double  stdev 
)

Generates a random vector within a random gaussian-distributed length in the xy plane.

Parameters
avgaverage of gaussian distribution.
stdevstandard deviation of gaussian distribution.
Returns
Vector3<double> vector.
A random vector is generated, the z-component set to zero, normalized 
and multiplied with a random value derived from a gaussian distribution.