Changeset 3099 in Sophya for trunk/SophyaLib/BaseTools/srandgen.h
- Timestamp:
- Nov 2, 2006, 3:37:05 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/BaseTools/srandgen.h
r2324 r3099 8 8 #include "machdefs.h" 9 9 #include <stdlib.h> 10 #ifdef __MWERKS__11 #include "unixmac.h"12 #endif13 10 11 /* ------- SPECIFIQUE Mac Darwin OSX <= 10.2 (gcc < 3.x) -------- */ 14 12 #if defined(Darwin) && defined(__GNUC__) && (__GNUC__ < 3) 15 13 #include "osx_values.h" … … 27 25 #define drand48() ((double)(random())/LONG_MAX) 28 26 #endif 27 /* ------- FIN SPECIFIQUE Mac OSX / Darwin V <= 10.2 --------- */ 29 28 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() ); } 34 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 */ 30 40 #define frand01() ( (float) drand48() ) 31 41 #define drand01() ( drand48() ) … … 35 45 #define drandpm1() ( 2. * drand01() - 1.) 36 46 #define ranfpm1() drandpm1() 47 #endif 37 48 38 49 struct tirage_alea { … … 62 73 ,double mx,double my,double sa,double sb,double teta); 63 74 75 int PoissRand(double mu); 76 64 77 TIREALEA *init_tirage_alea(int nbin,double xmin,double xmax,double (*fonc) (double)); 65 78 double tirage_alea(TIREALEA *alea); … … 70 83 #endif 71 84 85 /* -- Declaration d'une classe pour la centralier la doc -- Oct 2006 */ 86 #ifdef __cplusplus 87 namespace SOPHYA { 88 class 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 */ 72 102 #endif 73 103 104 #endif 105
Note:
See TracChangeset
for help on using the changeset viewer.