Changeset 3597 in Sophya for trunk/SophyaLib/BaseTools/srandgen.c
- Timestamp:
- Apr 21, 2009, 1:50:50 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/BaseTools/srandgen.c
r3408 r3597 187 187 Normal (Gaussian) random number generator (Mean=0., Sigma=1.) 188 188 */ 189 float NorRand(void) 190 { 191 double x,A,B; 192 193 LAB10: 194 A = drand01(); 195 if ( A == 0. ) goto LAB10; 196 B = drand01(); 197 x = sqrt(-2.*log(A))*cos(DeuxPi*B); 198 return( (float) x ); 189 double NorRand(void) 190 { 191 double A; 192 while( (A=drand01()) == 0.); 193 return sqrt(-2.*log(A))*cos(DeuxPi*drand01()); 199 194 } 200 195 … … 207 202 -- 208 203 */ 209 floatNorRand1(void)204 double NorRand1(void) 210 205 { 211 206 double b, x, y, gauss; … … 217 212 gauss = b*exp(-x*x/2.); 218 213 if ( gauss-y < 0. ) goto LAB10 ; 219 return ( (float) x );214 return x; 220 215 } 221 216 … … 233 228 double GauRnd(double am, double s) 234 229 { 235 double x,A,B; 236 237 LAB10: 238 A = drand01(); 239 if ( A == 0. ) goto LAB10; 240 B = drand01(); 241 x = am + s * sqrt(-2.*log(A))*cos(DeuxPi*B); 242 return(x); 230 double A; 231 while( (A=drand01()) == 0. ); 232 return am + s * sqrt(-2.*log(A))*cos(DeuxPi*drand01()); 243 233 } 244 234 … … 352 342 double c,s,X,Y; 353 343 354 LAB10: 355 s = drand01(); 356 if ( s == 0. ) goto LAB10; 344 while( (s = drand01()) == 0. ); 357 345 s = sqrt(-2.*log(s)); 358 346 c = DeuxPi * drand01(); … … 414 402 double a,b,sa; 415 403 if( ro <= -1. || ro >= 1. ) return(1); 416 LAB10: 417 b = drand01(); 418 if ( b == 0. ) goto LAB10; 404 while( (b=drand01()) == 0. ); 419 405 b = sqrt(-2.*log(b)); 420 406 a = DeuxPi * drand01();
Note:
See TracChangeset
for help on using the changeset viewer.