trick/trick_source/trick_utils/math/src/drandom_gaussian.c
Alex Lin 19025d77ad Standardize directory names
Reorganized.  Created a new top level include directory that will hold all of Trick's header files. Moved all of the Trick headers to this directory.  Created a libexec directory that holds all of the executables that users don't need to execute directly.  Changed all of the executables remaining in bin to start with "trick-".  In the sim_services directories changed all source files to find the Trick headers in their new location.  Since all of the include files are gone in sim_services, removed the src directories as well, moving all of the source files up a level.  Moved the makefiles, docs, man, and other architecture independent files into a top level share directory.  Renamed lib_${TRICK_HOST_CPU} to lib64 or lib depending on the platform we're currently on.

refs #63
2015-06-09 08:44:42 -05:00

45 lines
1.6 KiB
C

/*
PURPOSE: (Generate a random number consistent with a Gaussian distribution.)
ASSUMPTIONS AND LIMITATIONS: ((State spaces for independent processes requiring random numbers are not tracked.)
(Range is specified in standard deviations; i.e. if a range of 3 sigma is specified, then NO numbers greater than
the plus/minus 3 sigma value will be returned.) (Automatic Seed))
PROGRAMMERS: (((Robert W. Bailey) (LinCom Corp) (4/15/91) (Trick-CR-00009) (SAFR Model))) */
#include <stdlib.h>
#include "trick/trick_math.h"
#define MAX_VALUE 32768.0 /* 32768 = 2**15 */
double drandom_gaussian( /* Return: Random number consistent with Gaussian distribution */
double std_deviation, /* In: One standard deviation */
int range)
{ /* In: Plus/Minus range for Gaussian output in standard deviations */
int i;
double out;
double number = 0.0;
for (i = 0; i < 2 * range; i++) {
/* Call rand() 2*range times to get plus/minus range sigma output */
/* Normalize output of rand to the range of [-0.5,0.5] */
#ifdef __linux
out = (((double) rand()) / RAND_MAX) - 0.5;
#elif __APPLE__
out = (((double) rand()) / LONG_MAX) - 0.5;
#else
out = (((double) rand()) / MAX_VALUE) - 0.5;
#endif
/* Scale normalized output by one sigma value and sum to previous normalized values */
number += (std_deviation * out);
}
/* Resulting summed value is a gaussian random number */
return (number);
}