Real random number generator: a basic gaussian distribution
' gauss_rand_simple() ' is a function written in language C which return a real (double) value according to a gaussian distribution, that is mean 0 and variance 1 . #include <stdlib.h> #include <time.h> //necessary for time_t variable #include <math.h> #include <stdio.h> #define NUM 100; #define NSUM 25 double gauss_rand_simple() { double x = 0; int i; for(i = 0; i < NSUM; i++) x += (double)rand() / RAND_MAX; x -= NSUM / 2.0; x /= sqrt(NSUM / 12.0); return x; } } int main(int argc, char* argv[]) { time_t t; srand((unsigned int) time(&t)); double val = 0; for (int i=0; i < 10; ++i) { val = gauss_rand_simple(); printf("%f\n", val);