src/NFutil/random.cpp
/* Returns a random normally distributed number */
Returns a random normally distributed number
Returns a random normally distributed number
double NFutil::RANDOM_GAUSSIAN()
{
	if (initflag) {
		iRand.seed( (int) time(NULL));
		initflag=0;
    }
    if(haveNextGaussian)
    {
    	haveNextGaussian = false;
    	return nextGaussian;	
    }
	double v1=0, v2=0, s=0;
	do {
		v1 = 2 * dRandOpen()-1;
		v2 = 2 * dRandOpen()-1;
		s=v1*v1 + v2*v2;
	} while (s>=1 || s==0);
	double multiplier = sqrt(-2*log(s)/s);
	nextGaussian = v2*multiplier;
	haveNextGaussian = true;
	return v1*multiplier;
}
double NFutil :: RANDOM_GAUSSIAN ( ) { if ( initflag ) { iRand . seed ( ( int ) time ( NULL ) ) ; initflag = 0 ; } if ( haveNextGaussian ) { haveNextGaussian = false ; return nextGaussian ; } double v1 = 0 , v2 = 0 , s = 0 ; do { v1 = 2 * dRandOpen ( ) - 1 ; v2 = 2 * dRandOpen ( ) - 1 ; s = v1 * v1 + v2 * v2 ; } while ( s >= 1 || s == 0 ) ; double multiplier = sqrt ( -2 * log ( s ) / s ) ; nextGaussian = v2 * multiplier ; haveNextGaussian = true ; return v1 * multiplier ; }
Returns a random normally distributed number
Returns a random normally distributed number