Changeset 3615 in Sophya for trunk/SophyaLib/BaseTools/srandgen.h


Ignore:
Timestamp:
May 1, 2009, 1:34:31 PM (16 years ago)
Author:
cmv
Message:

Modifs relatives a l'introduction de RandomGeneratorInterface + delete de srandgen.c, cmv 01/05/2009

File:
1 edited

Legend:

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

    r3597 r3615  
    1 /* fonctions pour generateurs aleatoires    */
    2 /*                         cmv  23/06/94     */
    3 /*  R.Ansari 04/2000  Copie de nbrand.h .c  */
     1/* fonctions pour generateurs aleatoires  cmv 23/06/94 */
     2/*  Copie de nbrand.h .c  .Ansari 04/2000              */
     3/* interface avec RandomGeneratorInterface cmv 04/2009 */
    44
    55#ifndef SRANDGEN_H_SEEN
     
    88#include "machdefs.h"
    99#include <stdlib.h>
     10#include <complex>
     11#include "randinterf.h"
    1012
    11 /* ------- SPECIFIQUE Mac Darwin OSX  <= 10.2 (gcc < 3.x) -------- */
    12 #if defined(Darwin) &&  defined(__GNUC__) && (__GNUC__ < 3)
    13 #include "osx_values.h"
    14 /* Declaration de drand48 et srand48 etc , mis ds SysSpec
    15                                           Reza 11/02/2003 */
    16 #ifdef __cplusplus
    17 extern "C" {
    18 #endif
    19 unsigned short int * seed48(unsigned short int seed16v[3]);
    20 void srand48(long seedval);
    21 /* Faute de mieux pour le moment : */
    22 #ifdef __cplusplus
    23 }
    24 #endif
    25 #define drand48() ((double)(random())/LONG_MAX)
    26 #endif
    27 /* ------- FIN SPECIFIQUE Mac OSX / Darwin V <= 10.2 --------- */
     13/* Declaration en fonctions inline interface avec RandomGeneratorInterface global*/
    2814
    29 #ifdef __cplusplus
    30 /* Declaration en fonctions inlines pour du C++ */
    31 inline float frand01() { return ( (float) drand48() ); }
    32 inline double drand01() { return ( drand48() ); }
    33 inline double ranf01() { return ( drand48() ); }
     15namespace SOPHYA {
    3416
    35 inline float frandpm1() { return ( 2. * (float) drand48()  - 1.); }
    36 inline double drandpm1() { return ( 2. * drand48() - 1.); }
    37 inline double ranfpm1() { return ( 2. * drand48() - 1.); }
    38 #else
    39 /* les memes en define pour du C */
    40 #define frand01() ( (float) drand48() )
    41 #define drand01() ( drand48() )
    42 #define ranf01() drand01()
    4317
    44 #define frandpm1() ( 2. * frand01() - 1.)
    45 #define drandpm1() ( 2. * drand01() - 1.)
    46 #define ranfpm1() drandpm1()
    47 #endif
     18inline double drand01()
     19  {return RandomGeneratorInterface::GetGlobalRandGenP()->Flat01();}
     20inline double drandpm1()
     21  {return RandomGeneratorInterface::GetGlobalRandGenP()->Flatpm1();}
    4822
    49 struct tirage_alea {
    50   int Nbin;
    51   double Min,Max,Lbin;
    52   double *Tab;
    53 };
    54 typedef struct tirage_alea TIREALEA;
     23inline double NorRand()
     24  {return RandomGeneratorInterface::GetGlobalRandGenP()->Gaussian();}
     25inline double Gaussian(double sigma,double mu)
     26  {return RandomGeneratorInterface::GetGlobalRandGenP()->Gaussian(sigma,mu);}
    5527
    56 #ifdef __cplusplus
    57 extern "C" {
    58 #endif
     28inline complex< r_8 > ComplexGaussian()
     29  {return RandomGeneratorInterface::GetGlobalRandGenP()->ComplexGaussian();}
     30inline complex< r_8 > ComplexGaussian(double sig)
     31  {return RandomGeneratorInterface::GetGlobalRandGenP()->ComplexGaussian(sig);}
     32inline double ModComplexGaussian(double sig=1.)
     33  {return RandomGeneratorInterface::GetGlobalRandGenP()->ModComplexGaussian(sig);}
    5934
    60 void Ini_Ranf_Quick(long seed_val, int lp);
    61 void Ini_Ranf(unsigned short seed_16v[3], int lp);
    62 void Get_Ranf(unsigned short seed_16v[3], int lp);
    63 void Auto_Ini_Ranf(int lp);
     35inline double Poisson(double mu, double mumax=-1)
     36  {return RandomGeneratorInterface::GetGlobalRandGenP()->Poisson(mu,mumax);}
    6437
    65 void SetGauRange(double range);
    66 double NorRand1(void);
    67 double GauRnd1(double am, double s);
    68 double NorRand(void);
    69 double GauRnd(double am, double s);
    70 int NormCo(double *a,double *b
    71           ,double mx,double my,double sx,double sy,double ro);
    72 void NormGau(double *x,double *y
    73             ,double mx,double my,double sa,double sb,double teta);
     38inline double Exponential()
     39  {return RandomGeneratorInterface::GetGlobalRandGenP()->Exponential();}
    7440
    75 int PoissRand(double mu);
    76 unsigned long PoissRandLimit(double mu,double mumax /* =10. */ );
     41inline int Gaussian2DRho(double &x,double &y,double mx,double my,double sx,double sy,double ro)
     42  {return RandomGeneratorInterface::GetGlobalRandGenP()->Gaussian2DRho(x,y,mx,my,sx,sy,ro);}
     43inline void Gaussian2DAng(double &x,double &y,double mx,double my,double sa,double sb,double teta)
     44  {return RandomGeneratorInterface::GetGlobalRandGenP()->Gaussian2DAng(x,y,mx,my,sa,sb,teta);}
    7745
    78 TIREALEA *init_tirage_alea(int nbin,double xmin,double xmax,double (*fonc) (double));
    79 double tirage_alea(TIREALEA *alea);
    80 int end_tirage_alea(TIREALEA *alea);
     46inline void AutoInitRand(int lp)
     47  {return RandomGeneratorInterface::GetGlobalRandGenP()->AutoInit(lp);}
    8148
    82 #ifdef __cplusplus
    83 }
    84 #endif
     49inline void ShowRandom()
     50  {return RandomGeneratorInterface::GetGlobalRandGenP()->ShowRandom();}
     51
     52}  /* namespace SOPHYA */
    8553
    8654#endif
    87 
Note: See TracChangeset for help on using the changeset viewer.