![]() |
Bsoft 2.1.4
Bernard's software package
|
Functions for generating random sequences. More...
Functions | |
int | randseed (0) |
long | get_rand_max () |
Finds the maximum random number for a system. More... | |
double | irm (1.0L/get_rand_max()) |
long | random_seed () |
Gets a random seed and sets the flag. More... | |
int | random_array_uniform_chunk (float *r, long start, long end, double min, double range) |
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 stdev) |
Generates a value with a gaussian random distribution. More... | |
int | random_array_gaussian_chunk (float *r, long start, long end, double avg, double stdev) |
float * | random_array_gaussian (long n, double avg, double stdev) |
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... | |
int | random_array_poisson_chunk (float *r, long start, long end, double avg) |
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 stdev) |
Generates a value with a logistical random distribution. More... | |
int | random_array_logistical_chunk (float *r, long start, long end, double avg, double stdev) |
float * | random_array_logistical (long n, double avg, double stdev) |
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 stdev) |
Generates a random vector within a random gaussian-distributed length. More... | |
Vector3< double > | vector3_xy_random_gaussian (double avg, double stdev) |
Generates a random vector within a random gaussian-distributed length in the xy plane. More... | |
double | halton_number (long i, long b) |
double * | halton_sequence (long n, long b) |
Generates a Halton sequence. More... | |
Variables | |
int | verbose |
Functions for generating random sequences.
long get_rand_max | ( | ) |
Finds the maximum random number for a system.
Loops through random numbers to determine if the maximum is 2 or 4 bytes.
double halton_number | ( | long | i, |
long | b | ||
) |
double * halton_sequence | ( | long | n, |
long | b | ||
) |
Generates a Halton sequence.
n | length of sequence. |
b | base. |
The Halton sequence is a pseudo-random array.
double irm | ( | 1.0L/ | get_rand_max() | ) |
float * random_array_gaussian | ( | long | n, |
double | avg, | ||
double | stdev | ||
) |
Generates a series with a gaussian random distribution of values.
n | number of values. |
avg | average. |
stdev | standard deviation. |
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.
int random_array_gaussian_chunk | ( | float * | r, |
long | start, | ||
long | end, | ||
double | avg, | ||
double | stdev | ||
) |
float * random_array_logistical | ( | long | n, |
double | avg, | ||
double | stdev | ||
) |
Generates an array with a logistical random distribution.
n | number of values. |
avg | average. |
stdev | standard deviation. |
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)/2Reference: Press W.H. et al (1992) Numerical Recipes in C.
int random_array_logistical_chunk | ( | float * | r, |
long | start, | ||
long | end, | ||
double | avg, | ||
double | stdev | ||
) |
float * random_array_poisson | ( | int | n, |
double | avg | ||
) |
Generates a series with a poisson random distribution of values.
n | number of values. |
avg | average. |
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.
int random_array_poisson_chunk | ( | float * | r, |
long | start, | ||
long | end, | ||
double | avg | ||
) |
float * random_array_uniform | ( | long | n, |
double | min, | ||
double | max | ||
) |
Generates a series with a uniform random distribution.
n | number of values. |
min | minimum value. |
max | maximum value. |
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).
int random_array_uniform_chunk | ( | float * | r, |
long | start, | ||
long | end, | ||
double | min, | ||
double | range | ||
) |
double random_gaussian | ( | double | avg, |
double | stdev | ||
) |
Generates a value with a gaussian random distribution.
avg | average. |
stdev | standard deviation. |
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.
double random_logistical | ( | double | avg, |
double | stdev | ||
) |
Generates a value with a logistical random distribution.
avg | average. |
stdev | standard deviation. |
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)/2Reference: Press W.H. et al (1992) Numerical Recipes in C.
double random_poisson | ( | double | avg | ) |
Generates a value deviating from the average based on a poisson distribution.
avg | average. |
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.
long random_seed | ( | ) |
Gets a random seed and sets the flag.
The random seed is obtained using the program pid. A flag is set to prevent the seed from being generated multiple times.
int randseed | ( | 0 | ) |
Vector3< double > vector3_random | ( | const double | length | ) |
Generates a random vector within a defined sphere.
length | maximum vector length. |
A random vector is generated, normalized and multiplied with a random value smaller than the given length.
Vector3< double > vector3_random | ( | const double | min, |
const double | max | ||
) |
Generates a random vector within a defined cube.
min | minimum. |
max | maximum. |
Each vector element is set to a random value between the given minimum and maximum.
Generates a random vector within a defined cube.
min | minimum vector. |
max | maximum vector. |
Each vector element is set to a random value between the given minimum and maximum vectors.
Vector3< double > vector3_random_gaussian | ( | double | avg, |
double | stdev | ||
) |
Generates a random vector within a random gaussian-distributed length.
avg | average of gaussian distribution. |
stdev | standard deviation of gaussian distribution. |
A random vector is generated, normalized and multiplied with a random value derived from a gaussian distribution.
Vector3< double > vector3_random_unit_sphere | ( | ) |
Generates a random vector on the unit sphere.
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< double > vector3_xy_random_gaussian | ( | double | avg, |
double | stdev | ||
) |
Generates a random vector within a random gaussian-distributed length in the xy plane.
avg | average of gaussian distribution. |
stdev | standard deviation of gaussian distribution. |
A random vector is generated, the z-component set to zero, normalized and multiplied with a random value derived from a gaussian distribution.
|
extern |