Defines | |
| #define | QNAN sqrt(-1) |
Enumerations | |
| enum | RANDOMTYPE { RT_INVALID = -1, RT_DEGENERATE, RT_UNIFORM, RT_NORMAL, RT_LOGNORMAL, RT_BERNOULLI, RT_PARETO, RT_EXPONENTIAL, RT_SAMPLED } |
Functions | |
| int | random_apply (char *group_expression, char *property, RANDOMTYPE type,...) |
| Apply a random number to property of a group of objects. | |
| double | random_bernoulli (double p) |
| Generate a Bernoulli distributed random number. | |
| double | random_degenerate (double a) |
| Generate the same number always. | |
| double | random_exponential (double lambda) |
| Generate an exponentially distributed random number. | |
| int | random_init (void) |
| double | random_lognormal (double gmu, double gsigma) |
| Generate a log Gaussian distributed random number. | |
| double | random_normal (double m, double s) |
| Generate a Gaussian distributed random number. | |
| double | random_pareto (double m, double k) |
| Generate a Pareto distributed random number. | |
| double | random_sampled (unsigned n, double *x) |
| Generate a number randomly sample uniformly from a list. | |
| int | random_test (void) |
| Test random distributions. | |
| RANDOMTYPE | random_type (char *name) |
| Converts a distribution name to a RANDOMTYPE. | |
| double | random_uniform (double a, double b) |
| Generate a uniformly distributed random number. | |
| double | random_value (RANDOMTYPE type,...) |
| Generate a random value. | |
| double | randunit (void) |
| enum RANDOMTYPE |
| int random_apply | ( | char * | group_expression, | |
| char * | property, | |||
| RANDOMTYPE | type, | |||
| ... | ||||
| ) |
Apply a random number to property of a group of objects.
| group_expression | the group definition; see find_objects() |
| property | the property to update |
| type | the distribution type |
Definition at line 295 of file random.c.
References find_first(), find_next(), find_objects(), FL_GROUP, and object_set_double_by_name().
| double random_bernoulli | ( | double | p | ) |
Generate a Bernoulli distributed random number.
The probability density function for the Bernoulli distribution is
Note that the Bernoulli distribution is a discrete distribution.
| p | the probability of generating a 1 |
Definition at line 152 of file random.c.
References output_warning(), and randunit().
Referenced by random_test().
| double random_degenerate | ( | double | a | ) |
Generate the same number always.
This is the Dirac delta function:
The probability density function for the Dirac delta function
Definition at line 76 of file random.c.
References output_warning().
Referenced by random_test().
| double random_exponential | ( | double | lambda | ) |
Generate an exponentially distributed random number.
The exponential probability density function is
| lambda | the rate parameter lambda |
Definition at line 237 of file random.c.
References output_warning(), randunit(), and throw_exception().
Referenced by random_test().
| double random_lognormal | ( | double | gmu, | |
| double | gsigma | |||
| ) |
Generate a log Gaussian distributed random number.
The log-normal probability density function is
| gmu | the geometric mean |
| gsigma | the geometric standard deviation |
Definition at line 220 of file random.c.
References random_normal().
Referenced by random_test().
| double random_normal | ( | double | m, | |
| double | s | |||
| ) |
Generate a Gaussian distributed random number.
The probability density function for the Gaussian (normal) distribution is
Normally distributed random numbers are generated using the Box-Muller method:
double random_normal(double m, double s) { double r, a, b; do { a = 2*randunit()-1; b = 2*randunit()-1; r = a*a+b*b; } while (r>=1); return sqrt(-2*log(r)/r)*a*r*s+m; }
| m | the mean of the distribution |
| s | the standard deviation of the distribution |
Definition at line 133 of file random.c.
References output_warning(), PI, and randunit().
Referenced by random_lognormal(), and random_test().
| double random_pareto | ( | double | m, | |
| double | k | |||
| ) |
Generate a Pareto distributed random number.
The Pareto distribution is one in which the probability of drawing a number less than x is proportional to x^k. The probability density function of the Pareto distribution is
The cumulative density function is
.
| m | the minimum value |
| k | the k value |
Definition at line 198 of file random.c.
References output_warning(), randunit(), and throw_exception().
Referenced by random_test().
| double random_sampled | ( | unsigned | n, | |
| double * | x | |||
| ) |
Generate a number randomly sample uniformly from a list.
The probability that the value a is drawn from the sample is
Note that the sampled distriution is a discrete distribution.
| n | the number of samples in the list |
| x | the sample list |
Definition at line 171 of file random.c.
References output_warning(), QNAN, randunit(), and throw_exception().
Referenced by random_test().
| int random_test | ( | void | ) |
Test random distributions.
To run the self-test, use the --randtest command-line argument. The test results are output to the file specified by the global_testoutputfile variable.
Definition at line 404 of file random.c.
References max, min, output_test(), output_warning(), random_bernoulli(), random_degenerate(), random_exponential(), random_lognormal(), random_normal(), random_pareto(), random_sampled(), random_uniform(), and randunit().
Referenced by cmdarg_load().
| RANDOMTYPE random_type | ( | char * | name | ) |
Converts a distribution name to a RANDOMTYPE.
| name | the name of the distribution |
Definition at line 38 of file random.c.
References RT_BERNOULLI, RT_DEGENERATE, RT_EXPONENTIAL, RT_INVALID, RT_LOGNORMAL, RT_NORMAL, RT_PARETO, RT_SAMPLED, and RT_UNIFORM.
| double random_uniform | ( | double | a, | |
| double | b | |||
| ) |
Generate a uniformly distributed random number.
The probability density function for the uniform distribution is
Note that this uniform distribution includes a but does not include b.
| a | the minimum number |
| b | the maximum number |
Definition at line 98 of file random.c.
References output_warning(), and randunit().
Referenced by random_test().
| double random_value | ( | RANDOMTYPE | type, | |
| ... | ||||
| ) |