Changeset 3597 in Sophya for trunk/SophyaLib/BaseTools/srandgen.c


Ignore:
Timestamp:
Apr 21, 2009, 1:50:50 PM (16 years ago)
Author:
cmv
Message:

NorRand et GauRnd retournent double + elimination des label LAB: , cmv 21/04/2009

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/BaseTools/srandgen.c

    r3408 r3597  
    187187    Normal (Gaussian) random number generator (Mean=0., Sigma=1.)
    188188*/
    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 );
     189double NorRand(void)
     190{
     191 double A;
     192 while( (A=drand01()) == 0.);
     193 return sqrt(-2.*log(A))*cos(DeuxPi*drand01());
    199194}
    200195
     
    207202--
    208203*/
    209 float NorRand1(void)
     204double NorRand1(void)
    210205{
    211206double b, x, y, gauss;
     
    217212gauss = b*exp(-x*x/2.);
    218213if ( gauss-y < 0. ) goto LAB10 ;
    219 return( (float) x );
     214return  x;
    220215}
    221216
     
    233228double GauRnd(double am, double s)
    234229{
    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);
     230double A;
     231while( (A=drand01()) == 0. );
     232return am + s * sqrt(-2.*log(A))*cos(DeuxPi*drand01());
    243233}
    244234
     
    352342double c,s,X,Y;
    353343
    354 LAB10:
    355  s = drand01();
    356  if ( s == 0. ) goto LAB10;
     344while( (s = drand01()) == 0. );
    357345s = sqrt(-2.*log(s));
    358346c = DeuxPi * drand01();
     
    414402double a,b,sa;
    415403if( ro <= -1. || ro >= 1. ) return(1);
    416 LAB10:
    417  b = drand01();
    418  if ( b == 0. ) goto LAB10;
     404while( (b=drand01()) == 0. );
    419405b = sqrt(-2.*log(b));
    420406a = DeuxPi * drand01();
Note: See TracChangeset for help on using the changeset viewer.