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


Ignore:
Timestamp:
Nov 2, 2006, 3:37:05 PM (19 years ago)
Author:
ansari
Message:

Ajout PoissRand() + classe RandomGenerator / doc ds srandgen.h .cc , Reza 02/11/2006

File:
1 edited

Legend:

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

    r2324 r3099  
    88#include "machdefs.h"
    99#include <stdlib.h>
    10 #ifdef __MWERKS__
    11 #include "unixmac.h"
    12 #endif
    1310
     11/* ------- SPECIFIQUE Mac Darwin OSX  <= 10.2 (gcc < 3.x) -------- */
    1412#if defined(Darwin) &&  defined(__GNUC__) && (__GNUC__ < 3)
    1513#include "osx_values.h"
     
    2725#define drand48() ((double)(random())/LONG_MAX)
    2826#endif
     27/* ------- FIN SPECIFIQUE Mac OSX / Darwin V <= 10.2 --------- */
    2928
     29#ifdef __cplusplus
     30/* Declaration en fonctions inlines pour du C++ */
     31inline float frand01() { return ( (float) drand48() ); }
     32inline double drand01() { return ( drand48() ); }
     33inline double ranf01() { return ( drand48() ); }
     34
     35inline float frandpm1() { return ( 2. * (float) drand48()  - 1.); }
     36inline double drandpm1() { return ( 2. * drand48() - 1.); }
     37inline double ranfpm1() { return ( 2. * drand48() - 1.); }
     38#else
     39/* les memes en define pour du C */
    3040#define frand01() ( (float) drand48() )
    3141#define drand01() ( drand48() )
     
    3545#define drandpm1() ( 2. * drand01() - 1.)
    3646#define ranfpm1() drandpm1()
     47#endif
    3748
    3849struct tirage_alea {
     
    6273            ,double mx,double my,double sa,double sb,double teta);
    6374
     75int PoissRand(double mu);
     76
    6477TIREALEA *init_tirage_alea(int nbin,double xmin,double xmax,double (*fonc) (double));
    6578double tirage_alea(TIREALEA *alea);
     
    7083#endif
    7184
     85/* -- Declaration d'une classe pour la centralier la doc -- Oct 2006 */
     86#ifdef __cplusplus
     87namespace SOPHYA {
     88class RandomGenerator {
     89 public:
     90  /*! \brief Automatic initialization through Auto_Ini_Ranf() */
     91  static inline void AutoInit(int lp=0) { Auto_Ini_Ranf(lp); return; }
     92  /*! \brief Return a random number \b r with a flat distribution  0<=r<=1 */
     93  static inline double Flat01() { return drand48(); }
     94  /*! \brief Return a random number \b r with a flat distribution  -1<=r<=1 */
     95  static inline double Flatpm1() { return drandpm1(); }
     96  /*! \brief Return a random number following a zero mean gaussian distribution  */
     97  static inline double Gaussian(double sigma=1.) { return GauRnd(0., sigma); }
     98  /*! \brief Return a random number following a Poisson distribution with mean \b mu  */
     99  static inline int    Poisson(double mu) { return PoissRand(mu); }
     100};
     101} /* namespace SOPHYA */
    72102#endif
    73103
     104#endif
     105
Note: See TracChangeset for help on using the changeset viewer.