tcod_sys/libtcod/src/mersenne_c.c
double TCOD_random_get_gaussian_double (TCOD_random_t mersenne, double mean, double std_deviation) {
	double x1, x2, w, y1;
	static double y2;
	static bool again = false;
	double ret;
	if (again)
		ret = mean + y2 * std_deviation;
	else {
        mersenne_data_t *r = NULL;
		if (!mersenne) mersenne=TCOD_random_get_instance();
		r = (mersenne_data_t *)mersenne;
		/* MT */
		if (r->algo == TCOD_RNG_MT) {
			do {
				x1 = frandom01(r) * 2.0 - 1.0;
				x2 = frandom01(r) * 2.0 - 1.0;
				w = x1 * x1 + x2 * x2;
			} while (w >= 1.0);
		}
		/* CMWC */
		else {
			uint32_t number;
			do {
				CMWC_GET_NUMBER(number)
				x1 = number * rand_div_double * 2.0 - 1.0;
				CMWC_GET_NUMBER(number)
				x2 = number * rand_div_double * 2.0 - 1.0;
				w = x1 * x1 + x2 * x2;
			} while (w >= 1.0);
		}
		w = sqrt((-2.0 * log(w)) / w);
		y1 = x1 * w;
		y2 = x2 * w;
		ret = mean + y1 * std_deviation;
	}
	again = !again;
	return ret;
}
/* Box-Muller transform (Gaussian distribution) */
Box-Muller transform (Gaussian distribution)
Box - Muller transform ( Gaussian distribution )
double TCOD_random_get_gaussian_double (TCOD_random_t mersenne, double mean, double std_deviation) {
	double x1, x2, w, y1;
	static double y2;
	static bool again = false;
	double ret;
	if (again)
		ret = mean + y2 * std_deviation;
	else {
        mersenne_data_t *r = NULL;
		if (!mersenne) mersenne=TCOD_random_get_instance();
		r = (mersenne_data_t *)mersenne;
		if (r->algo == TCOD_RNG_MT) {
			do {
				x1 = frandom01(r) * 2.0 - 1.0;
				x2 = frandom01(r) * 2.0 - 1.0;
				w = x1 * x1 + x2 * x2;
			} while (w >= 1.0);
		}
		else {
			uint32_t number;
			do {
				CMWC_GET_NUMBER(number)
				x1 = number * rand_div_double * 2.0 - 1.0;
				CMWC_GET_NUMBER(number)
				x2 = number * rand_div_double * 2.0 - 1.0;
				w = x1 * x1 + x2 * x2;
			} while (w >= 1.0);
		}
		w = sqrt((-2.0 * log(w)) / w);
		y1 = x1 * w;
		y2 = x2 * w;
		ret = mean + y1 * std_deviation;
	}
	again = !again;
	return ret;
}
double TCOD_random_get_gaussian_double ( TCOD_random_t mersenne , double mean , double std_deviation ) { double x1 , x2 , w , y1 ; static double y2 ; static bool again = false ; double ret ; if ( again ) ret = mean + y2 * std_deviation ; else { mersenne_data_t * r = NULL ; if ( ! mersenne ) mersenne = TCOD_random_get_instance ( ) ; r = ( mersenne_data_t * ) mersenne ; if ( r -> algo == TCOD_RNG_MT ) { do { x1 = frandom01 ( r ) * 2.0 - 1.0 ; x2 = frandom01 ( r ) * 2.0 - 1.0 ; w = x1 * x1 + x2 * x2 ; } while ( w >= 1.0 ) ; } else { uint32_t number ; do { CMWC_GET_NUMBER ( number ) x1 = number * rand_div_double * 2.0 - 1.0 ; CMWC_GET_NUMBER ( number ) x2 = number * rand_div_double * 2.0 - 1.0 ; w = x1 * x1 + x2 * x2 ; } while ( w >= 1.0 ) ; } w = sqrt ( ( -2.0 * log ( w ) ) / w ) ; y1 = x1 * w ; y2 = x2 * w ; ret = mean + y1 * std_deviation ; } again = ! again ; return ret ; }
Box-Muller transform (Gaussian distribution)
Box - Muller transform ( Gaussian distribution )
/* MT */ /* CMWC */